﻿/*
#**************************************************************************
#  openSIS is a student information system for public and non-public 
#  schools from Open Solutions for Education, Inc. web: www.os4ed.com
#
#  openSIS is  web-based, open source, and comes packed with features that 
#  include student demographic info, scheduling, grade book, attendance, 
#  report cards, eligibility, transcripts, parent portal, 
#  student portal and more.   
#
#  Visit the openSIS web site at http://www.opensis.com to learn more.
#  If you have question regarding this system or the license, please send 
#  an email to info@os4ed.com.
#
#  This program is released under the terms of the GNU General Public License  
#  as  published by the Free Software Foundation, version 2 of the License. 
#  See license.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#**************************************************************************** 
*/

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using OSISToolTip;
using System.IO;
using OSISDynamicTranslation;
using OpenSISInstall;
using OpenSIS.OpenSISWCFServiceReference;
using DatePicker;
using OpenSISStudentListControl;

public partial class Student_AddStudent : System.Web.UI.Page
{
    DropDownList ddlSchoolName = new DropDownList();
    DropDownList ddlFullYear = new DropDownList();
    DropDownList ddlLevel1 = new DropDownList();
    static int AddSet = 1;
    int InitialFieldId = 0;
    static string AddTableList = "";
    private HtmlTableRow dTRow;
    private HtmlTableCell dTCell;
    private HtmlTableRow dTAddRow;
    private HtmlTableCell dTAddCell;
    private HtmlTableCell dTAddCell1;
    private HtmlTableCell dTAddCell2;
    private HtmlTableCell dTCell1;
    private HtmlTableCell dTCell2;
    private HtmlTableCell dTAdditionalContCell;
    private HtmlTableCell dTAdditionalContCell1;
    private HtmlTableCell dTAdditionalContCell2;
    private HtmlTableRow dTAdditionalContRow;
    //For Dynamic Special
    //private HtmlTable dtSpeicalEd;
    private HtmlTableCell dtSpeicalEdCell;
    private HtmlTableCell dtSpeicalEdCell1;
    private HtmlTableCell dtSpeicalEdCell2;
    private HtmlTableRow dtSpeicalEdRow;
    //For Dynamic Gifted
    private HtmlTableCell dtGiftAddCell;
    private HtmlTableCell dtGiftAddCell1;
    private HtmlTableCell dtGiftAddCell2;
    private HtmlTableRow dtGiftAddRow;
    private HtmlTable dTAdd;
    DynamicTranslation DTL = new DynamicTranslation();
    private static string langto;
    StudentListControl StuListCont = new StudentListControl();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        langto = System.Web.HttpContext.Current.Session["MLUICulture"].ToString();
        btnAdditionalConSave.Text = DTL.Translate(btnAdditionalConSave.Text, "en", langto);
        btnSave.Text = DTL.Translate(btnSave.Text, "en", langto);
        btnCancel.Text = DTL.Translate(btnCancel.Text, "en", langto);

        if (!Page.IsPostBack)
        {
            AddTableList = "";
            AddSet = 1;
            //PopulateMasterDropdownFullYear();
            Session["Enroltable"] = null;
            Session["SchoolInfo"] = null;             
        }
        if (Session["StudentImage"] != null)
        {
            // imgStudentPhoto.Src = Session["StudentImage"].ToString();
            //divPhotoUpload.Attributes.Clear();
            divPhotoUpload.Style.Add("background-image", "url(" + Session["StudentImage"].ToString().Replace("~", "..") + ")");
        }
        PopulateCategoryTree();
        PopupateInitialFields();

        //**********
       
    }

    public void PopulateCategoryTree()
    {
        try
        {
            //StudentBL schoolcategory = new StudentBL();
            //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            //schoolcategory.SchoolID = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
            IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
            // ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);
            if (SchoolID == 0)
            {
                SchoolID = Convert.ToInt32(Session["SchoolID"].ToString());
            }
            // DataTable dt = schoolcategory.GetSchoolSpecificCategory();
            DataTable dt = schoolcategory.GetSchoolSpecificCategoryStudentBusiness(SchoolID.ToString(), Session["MLUICulture"].ToString());
            TreeView1.Nodes.Clear();
            string[,] YearNodes = new string[100, 4];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                TreeNode TreeNodeCategory = new TreeNode();
                YearNodes[i, 0] = dt.Rows[i]["Cat_Name"].ToString();
                YearNodes[i, 1] = dt.Rows[i]["Cat_Id"].ToString();
                TreeNodeCategory.Text = YearNodes[i, 0];
                TreeNodeCategory.Value = YearNodes[i, 1] + "," + i;
                TreeView1.Nodes.Add(TreeNodeCategory);
                TreeView1.ExpandAll();
            }
        }
        catch { }
    }

    protected void PopupateInitialFields()
    {
        //EntryFormLayoutBL categoryfields = new EntryFormLayoutBL();
        OpenSISWCFServiceStudentFormLayoutClient categoryfields = new OpenSISWCFServiceStudentFormLayoutClient();
        try
        {
            //StudentBL stcategory = new StudentBL();
            //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            //stcategory.SchoolID = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
            IopenSISServiceStudentClient stcategory = new IopenSISServiceStudentClient();
            ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);
            //DataTable dtCatId = stcategory.GetFirstCategory();
            DataTable dtCatId = stcategory.GetFirstCategoryStudentBusiness(SchoolID);
            if (dtCatId.Rows.Count > 0)
            {
                if (hdnInitialCatId.Value.ToString() == "")
                {
                    hdnCatId.Value = dtCatId.Rows[0][0].ToString();
                }
                else
                {
                    hdnCatId.Value = hdnInitialCatId.Value.ToString();
                }
                if (hdnCatId.Value.ToString() == "1")
                {
                    divPhotoUpload.Style.Add("Display", "block");
                    divOuter.Style.Add("Display", "block");
                }
                else
                {
                    divPhotoUpload.Style.Add("Display", "none");
                    divOuter.Style.Add("Display", "none");
                }
                foreach (TreeNode tn in TreeView1.Nodes)
                {
                    string t = tn.Value.Split(",".ToCharArray())[0];
                    if (t == hdnCatId.Value.ToString())
                    {
                        tn.Selected = true;
                    }
                }
                if (hdnCatId.Value.ToString() != "3")
                {
                    btnImmuAdd.Visible = false;
                    ibtnAlertAdd.Visible = false;
                    ibtnNursevisitAdd.Visible = false;
                    GVImmunization.Visible = false;
                    GVMedicalAlert.Visible = false;
                    GVNurseVisitRec.Visible = false;
                    ibtnVace.Visible = false;
                    rptrVaceField.Visible = false;
                    rptMedicalInfo.Visible = false;
                    TMInfo.Visible = false;
                    tblProgram.Visible = false;
                    if (hdnCatId.Value.ToString() != "5")
                    {
                        gvEnrInfo.Visible = false;
                        rptrSchlInfo.Visible = false;
                        tblSchEnrInfo.Visible = false;
                        if (hdnCatId.Value.ToString() != "4")
                        {
                            if (hdnCatId.Value.ToString() != "8")
                            {
                                //stcategory.CatId = Convert.ToInt32(hdnCatId.Value);
                                //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                                //stcategory.SchoolID = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
                                //// TreeView1.Nodes[Convert.ToInt32(hdnCatId.Value)].Selected = true;
                                //string CatName = TreeView1.SelectedNode.Text.ToString();
                                //DataTable dt = stcategory.GetFieldsByCategory();
                                //ibtnAdd.Visible = false;
                                int CatId = Convert.ToInt32(hdnCatId.Value);
                                // ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                                SchoolID = Convert.ToInt32(Session["SchoolID"]);
                                // TreeView1.Nodes[Convert.ToInt32(hdnCatId.Value)].Selected = true;
                                string CatName = TreeView1.SelectedNode.Text.ToString();
                                DataTable dt = stcategory.GetFieldsByCategoryStudentBusiness(SchoolID, CatId, Session["MLUICulture"].ToString());
                                ibtnAdd.Visible = false;                                
                                this.dTable.CellPadding = 2;
                                this.dTable.CellSpacing = 0;
                                this.dTable.Border = 0;
                                this.dTable.Width = "100%";
                                //this.dTable.Attributes.Add("class", "darkblue_content");
                                int tRows;
                                int tCells = 2;
                                int tCellsmod = Convert.ToInt32(dt.Rows.Count % tCells);
                                int tCellsquotient = Convert.ToInt32(dt.Rows.Count / tCells);
                                if (tCellsmod != 0)
                                {
                                    tCellsquotient = tCellsquotient + 1;
                                    int j = dt.Rows.Count;
                                    DataRow dr = dt.NewRow();
                                    dt.Rows.Add(dr);
                                }
                                this.dTRow = new HtmlTableRow();
                                this.dTCell = new HtmlTableCell();
                                this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + CatName.ToString() + "</div>";
                                this.dTCell.ColSpan = 6;
                                this.dTRow.Cells.Add(dTCell);
                                this.dTable.Rows.Insert(0, dTRow);
                                for (tRows = 0; tRows < tCellsquotient; tRows++)
                                {
                                    tRows = 0;
                                    if (dt.Rows.Count > 0 || dt.Rows.Count != 0)
                                    {
                                        this.dTRow = new HtmlTableRow();
                                        for (tCells = 0; tCells < 2; tCells++)
                                        {
                                            this.dTCell = new HtmlTableCell();
                                            this.dTCell1 = new HtmlTableCell();
                                            this.dTCell2 = new HtmlTableCell();
                                            dTCell.Attributes.Add("class", "student_grid");
                                            if (dt.Rows[tRows]["FieldName"].ToString() != "")
                                            {
                                                this.dTCell.InnerHtml = "<div class='blue_bold'>" + dt.Rows[tRows]["FieldName"].ToString() + "</div>";
                                                this.dTCell1.InnerText = ":";
                                            }
                                            dTCell.Align = "left";
                                            dTCell2.Align = "left";
                                            int FieldId = 0;
                                            if (dt.Rows[tRows]["FieldId"].ToString() != "")
                                            {
                                                FieldId = Convert.ToInt32(dt.Rows[tRows]["FieldId"]);
                                            }
                                            if (dt.Rows[tRows]["FieldType"].ToString() == "1")
                                            {
                                                TextBox txt = new TextBox();
                                                HiddenField hdnFieldId = new HiddenField();
                                                txt.ID = "txt" + InitialFieldId;
                                                hdnFieldId.ID = "hdn" + InitialFieldId;
                                                hdnFieldId.Value = dt.Rows[tRows]["FieldId"].ToString() + "_" + dt.Rows[tRows]["Default_Custom"].ToString();
                                                txt.CssClass = "textbox2";
                                                this.dTCell2.Controls.Add(txt);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            if (dt.Rows[tRows]["FieldType"].ToString() == "2")
                                            {
                                                CheckBoxList chk = new CheckBoxList();
                                                HiddenField hdnFieldId = new HiddenField();
                                                chk.ID = "chk" + InitialFieldId;
                                                hdnFieldId.ID = "hdn" + InitialFieldId;
                                                hdnFieldId.Value = dt.Rows[tRows]["FieldId"].ToString() + "_" + dt.Rows[tRows]["Default_Custom"].ToString();
                                                chk.RepeatDirection = RepeatDirection.Horizontal;
                                                if (dt.Rows[tRows]["Default_Custom"].ToString() == "C")
                                                {
                                                    //categoryfields.populatedynamicrchk(ref chk);
                                                    StuListCont.populatedynamicrchk(ref chk, FieldId);
                                                }
                                                this.dTCell2.Controls.Add(chk);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            if (dt.Rows[tRows]["FieldType"].ToString() == "3")
                                            {
                                                RadioButtonList rdb = new RadioButtonList();
                                                HiddenField hdnFieldId = new HiddenField();
                                                rdb.ID = "rdb" + InitialFieldId;
                                                hdnFieldId.ID = "hdn" + InitialFieldId;
                                                rdb.RepeatDirection = RepeatDirection.Horizontal;
                                                hdnFieldId.Value = dt.Rows[tRows]["FieldId"].ToString() + "_" + dt.Rows[tRows]["Default_Custom"].ToString();
                                                if (dt.Rows[tRows]["Default_Custom"].ToString() == "D")
                                                {
                                                    if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 10)
                                                    {
                                                        //categoryfields.PopulateGender(ref rdb);
                                                        StuListCont.PopulateGender(ref rdb);
                                                    }
                                                }
                                                if (dt.Rows[tRows]["Default_Custom"].ToString() == "C")
                                                {
                                                    //categoryfields.populatedynamicrbtn(ref rdb);
                                                    StuListCont.populatedynamicrbtn(ref rdb, FieldId);
                                                }
                                                this.dTCell2.Controls.Add(rdb);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            if (dt.Rows[tRows]["FieldType"].ToString() == "4")
                                            {
                                                DropDownList ddl = new DropDownList();
                                                HiddenField hdnFieldId = new HiddenField();
                                                ddl.ID = "ddl" + InitialFieldId;
                                                hdnFieldId.ID = "hdn" + InitialFieldId;
                                                ddl.CssClass = "dropdown2";
                                                hdnFieldId.Value = dt.Rows[tRows]["FieldId"].ToString() + "_" + dt.Rows[tRows]["Default_Custom"].ToString();
                                                if (dt.Rows[tRows]["Default_Custom"].ToString() == "D")
                                                {
                                                    if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 11)//ETHNICITY
                                                    {
                                                        // categoryfields.populateEthnicity(ref ddl);
                                                        StuListCont.populateEthnicity(ref ddl, Convert.ToInt32(Session["SchoolID"]));
                                                    }
                                                    if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 15 || Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 16)//LANGUAGE
                                                    {
                                                        //categoryfields.populateLanguage(ref ddl);
                                                        StuListCont.populateLanguage(ref ddl);
                                                    }
                                                    if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 18)//COUNTRY
                                                    {
                                                        //categoryfields.populateCountry(ref ddl);
                                                        StuListCont.populateCountry(ref ddl);
                                                    }
                                                    if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 120)//START CONDITION
                                                    {
                                                        // vmlBL.populateCountry(ref ddl);
                                                        //categoryfields.PopulateEnrollCdn(ref ddl);
                                                        StuListCont.PopulateEnrollCdn(ref ddl);
                                                    }
                                                    if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 110)//Calender
                                                    {

                                                        //stcategory.populatecalender(ref ddl);
                                                        StuListCont.populatecalender(ref ddl, SchoolID);
                                                    }
                                                    //******************6/2/2010**************
                                                    if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 210)//Religion
                                                    {                                                        
                                                        StuListCont.populateReligion(ref ddl);
                                                    }
                                                }
                                                if (dt.Rows[tRows]["Default_Custom"].ToString() == "C")
                                                {
                                                    //categoryfields.populatedynamicddl(ref ddl);
                                                    StuListCont.populatedynamicddl(ref ddl, FieldId);
                                                }
                                                this.dTCell2.Controls.Add(ddl);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            if (dt.Rows[tRows]["FieldType"].ToString() == "5")
                                            {
                                                Label lbl = new Label();
                                                HiddenField hdnFieldId = new HiddenField();
                                                lbl.ID = "lbl" + InitialFieldId;
                                                hdnFieldId.ID = "hdn" + InitialFieldId;
                                                hdnFieldId.Value = dt.Rows[tRows]["FieldId"].ToString() + "_" + dt.Rows[tRows]["Default_Custom"].ToString();
                                                //StudentBL stbl2 = new StudentBL();
                                                this.dTCell2.Controls.Add(lbl);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            //*******************28/04/2010*******************
                                            if (dt.Rows[tRows]["FieldType"].ToString() == "6")
                                            {                                              
                                                HiddenField hdnFieldId = new HiddenField();
                                                hdnFieldId.ID = "hdn" + InitialFieldId;
                                                hdnFieldId.Value = dt.Rows[tRows]["FieldId"].ToString() + "_" + dt.Rows[tRows]["Default_Custom"].ToString();
                                                Control control = new Control();
                                                control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx"); 
                                                control.ID = "uc" + InitialFieldId;     
                                                this.dTCell2.Controls.Add(control);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            //************************************************
                                            this.dTRow.Controls.Add(dTCell);
                                            this.dTRow.Controls.Add(dTCell1);
                                            this.dTRow.Controls.Add(dTCell2);
                                            dt.Rows.RemoveAt(0);
                                            tRows = 0;
                                            InitialFieldId++;
                                        }
                                        this.dTable.Controls.Add(dTRow);
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                this.dTRow = new HtmlTableRow();
                                this.dTCell = new HtmlTableCell();
                                this.dTCell.InnerHtml = "<div class='clear_small'></div>";
                                this.dTCell.ColSpan = 6;
                                this.dTRow.Cells.Add(dTCell);
                                this.dTable.Rows.Insert(tCellsquotient + 1, dTRow);
                                phAllFieldHolder.Controls.Add(dTable);
                            }
                            else
                            {
                                //Special and gifted in populateinitialfield
                                tblSchEnrInfo.Visible = false;
                                TMInfo.Visible = false;
                                tblProgram.Visible = true;
                                ibtnAdd.Visible = false;
                                btnPrev.Visible = true;
                                //StudentBL schoolcategory = new StudentBL();
                                //schoolcategory.SchoolID = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
                                //DataTable dtspec = schoolcategory.PopulateSpecialField();
                                IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
                                SchoolID = Convert.ToInt32(Session["SchoolID"]);
                                DataTable dtspec = schoolcategory.PopulateSpecialFieldStudentBusiness(SchoolID, Session["MLUICulture"].ToString());
                                rptrSpecial.DataSource = dtspec;
                                rptrSpecial.DataBind();
                                //DataTable dtgift = schoolcategory.PopulateGiftField();
                                DataTable dtgift = schoolcategory.PopulateGiftFieldStudentBusiness(SchoolID, Session["MLUICulture"].ToString());
                                rptrGiftforadd.DataSource = dtgift;
                                rptrGiftforadd.DataBind();
                            }
                        }
                        else
                        {
                            //enrollment popuilateinitialfields
                            DropDownList ddl = new DropDownList();
                            ibtnEnrInfo.Visible = true;
                            tblSchEnrInfo.Visible = true;
                            gvEnrInfo.Visible = true;
                            rptrSchlInfo.Visible = true;
                            //StudentBL schoolcategory = new StudentBL();
                            IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
                            // hdnCatId.Value = dt.Rows[0][0].ToString();
                            //stcategory.CatId = Convert.ToInt32(hdnCatId.Value);
                            int CatId = Convert.ToInt32(hdnCatId.Value);
                            //DataTable dtschlinfo = stcategory.GetFieldsByCategory();
                            DataTable dtschlinfo = stcategory.GetFieldsByCategoryStudentBusiness(SchoolID, CatId, Session["MLUICulture"].ToString());
                            rptrSchlInfo.DataSource = dtschlinfo;
                            rptrSchlInfo.DataBind();
                            DataTable SessiondtEnrol = (DataTable)Session["Enroltable"];
                            if (SessiondtEnrol != null)
                            {
                                gvEnrInfo.DataSource = SessiondtEnrol;
                                gvEnrInfo.DataBind();
                            }
                            else
                            {
                                DataTable dtEnrol = new DataTable();
                                dtEnrol.Columns.Add("AttStrtDate");
                                dtEnrol.Columns.Add("ExitDate");
                                dtEnrol.Columns.Add("ExitCode");
                                dtEnrol.Columns.Add("Exitreason");
                                dtEnrol.Columns.Add("StartCondition");
                                //added
                                dtEnrol.Columns.Add("ExitCodeValue");
                                DataRow dr = dtEnrol.NewRow();
                                dtEnrol.Rows.Add(dr);
                                gvEnrInfo.DataSource = dtEnrol;
                                gvEnrInfo.DataBind();
                            }
                        }
                    }
                    else
                    {
                        //StudentBL schoolcategory = new StudentBL();
                        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
                        // hdnCatId.Value = dt.Rows[0][0].ToString();
                        //stcategory.CatId = Convert.ToInt32(hdnCatId.Value);
                        int CatId = Convert.ToInt32(hdnCatId.Value);
                        //schoolcategory.CatId = Convert.ToInt32(hdnCatId.Value);
                        hdnInitialCatId.Value = hdnCatId.Value;
                        btnImmuAdd.Visible = true;
                        ibtnAlertAdd.Visible = true;
                        ibtnNursevisitAdd.Visible = true;
                        GVImmunization.Visible = true;
                        GVMedicalAlert.Visible = true;
                        GVNurseVisitRec.Visible = true;
                        ibtnVace.Visible = true;
                        rptrVaceField.Visible = true;
                        rptMedicalInfo.Visible = true;
                        TMInfo.Visible = true;
                        DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
                        if (SessiondtImmu != null)
                        {
                            GVImmunization.DataSource = SessiondtImmu;
                            GVImmunization.DataBind();
                        }
                        else
                        {
                            DataTable dtImmu = new DataTable();
                            dtImmu.Columns.Add("Type");
                            dtImmu.Columns.Add("Date");
                            dtImmu.Columns.Add("Comment");
                            dtImmu.Columns.Add("Typevalue");
                            DataRow dr = dtImmu.NewRow();
                            dtImmu.Rows.Add(dr);
                            GVImmunization.DataSource = dtImmu;
                            GVImmunization.DataBind();
                        }
                        DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
                        if (SessiondtAlert != null)
                        {
                            GVMedicalAlert.DataSource = SessiondtAlert;
                            GVMedicalAlert.DataBind();
                        }
                        else
                        {
                            DataTable dtAlert = new DataTable();
                            dtAlert.Columns.Add("Alert");
                            DataRow dr = dtAlert.NewRow();
                            dtAlert.Rows.Add(dr);
                            GVMedicalAlert.DataSource = dtAlert;
                            GVMedicalAlert.DataBind();
                        }
                        DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
                        if (SessiondtNurseVisit != null)
                        {
                            GVNurseVisitRec.DataSource = SessiondtNurseVisit;
                            GVNurseVisitRec.DataBind();
                        }
                        else
                        {
                            DataTable dtNurseVisit = new DataTable();
                            dtNurseVisit.Columns.Add("Date");
                            dtNurseVisit.Columns.Add("TimeIn");
                            dtNurseVisit.Columns.Add("TimeOut");
                            dtNurseVisit.Columns.Add("Reason");
                            dtNurseVisit.Columns.Add("Result");
                            dtNurseVisit.Columns.Add("Comments");
                            DataRow dr = dtNurseVisit.NewRow();
                            dtNurseVisit.Rows.Add(dr);
                            GVNurseVisitRec.DataSource = dtNurseVisit;
                            GVNurseVisitRec.DataBind();
                        }
                        DataTable dtMedicalInfo = new DataTable();
                        //dtMedicalInfo = schoolcategory.GetMedicalInfoFields();
                        dtMedicalInfo = schoolcategory.GetMedicalInfoFieldsStudentBusiness(SchoolID, CatId);
                        rptMedicalInfo.DataSource = dtMedicalInfo;
                        rptMedicalInfo.DataBind();
                        //DataTable dtVaccinationDetails = new DataTable();
                        //dtVaccinationDetails.Columns.Add("Vaccination_Code");
                        //dtVaccinationDetails.Columns.Add("Vaccination_Name");
                        //dtVaccinationDetails.Columns.Add("Vaccination_Date");
                        //dtVaccinationDetails.Columns.Add("Vaccination_Expiry_Date");
                        //dtVaccinationDetails.Columns.Add("Waiver");
                        //DataRow drvacc = dtVaccinationDetails.NewRow();
                        //dtVaccinationDetails.Rows.Add(drvacc);
                        //GVVccination.DataSource = dtVaccinationDetails;
                        //GVVccination.DataBind();
                        //PopulateVccinationGridview();
                        DataTable dtVcea = new DataTable();
                        dtVcea = schoolcategory.GetVaccinationFieldsStudentBusiness(SchoolID, CatId);
                        //dtVcea = schoolcategory.GetVaccinationFields();
                        // dtVcea = schoolcategory.PopulateSpecialField();
                        rptrVaceField.DataSource = dtVcea;
                        rptrVaceField.DataBind();
                        DataTable SessiondtGift = (DataTable)Session["VaccinationForInsert"];
                        if (SessiondtGift != null)
                        {
                            rptrVccination.DataSource = SessiondtGift;
                            rptrVccination.DataBind();
                        }
                    }
                }
                else
                {
                    TMInfo.Visible = false;
                    tblSchEnrInfo.Visible = false;
                    tblProgram.Visible = false;
                    // StudentInfoViewBL schoolcategory = new StudentInfoViewBL();
                    //StudentBL schoolcategory = new StudentBL();
                    //StudentSetupBL StSuBL = new StudentSetupBL();
                    IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
                    OpenSISWCFServiceStudentSetupClient StSuBL = new OpenSISWCFServiceStudentSetupClient();
                    hdnCatId.Value = hdnInitialCatId.Value;
                    //hdnInitialCatId.Value = hdnCatId.Value;
                    //schoolcategory.CatId = Convert.ToInt32(hdnCatId.Value);
                    int CatId = Convert.ToInt32(hdnCatId.Value);
                    //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                    //schoolcategory.SchoolID = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
                    // TreeView1.Nodes[Convert.ToInt32(hdnCatId.Value)].Selected = true;
                    // string CatName = TreeView1.SelectedNode.Text.ToString();
                    DataTable dtFields = schoolcategory.GetFieldsByCategoryStudentBusiness(SchoolID, CatId, Session["MLUICulture"].ToString());
                    ibtnAdd.Visible = true;
                    // int FieldId = 0;
                    this.dTable.CellPadding = 2;
                    this.dTable.CellSpacing = 0;
                    this.dTable.Border = 0;
                    this.dTable.Width = "100%";
                    this.dTable.Attributes.Remove("class");
                    int tRows;
                    int tCells = 2;
                    int tCellsmod = Convert.ToInt32(dtFields.Rows.Count % tCells);
                    int tCellsquotient = Convert.ToInt32(dtFields.Rows.Count / tCells);
                    if (tCellsmod != 0)
                    {
                        tCellsquotient = tCellsquotient + 1;
                        DataRow dr = dtFields.NewRow();
                        dtFields.Rows.Add(dr);
                    }
                    for (tRows = 0; tRows < tCellsquotient; tRows++)
                    {
                        // tRows = 0;
                        int L = 0;
                        if (dtFields.Rows.Count > 0 || dtFields.Rows.Count != 0)
                        {
                            this.dTRow = new HtmlTableRow();
                            for (tCells = 0; tCells < 2; tCells++)
                            {
                                this.dTAdd = new HtmlTable();
                                this.dTAdd.CellPadding = 2;
                                this.dTAdd.CellSpacing = 0;
                                this.dTAdd.Border = 0;
                                this.dTAdd.Width = "100%";
                                this.dTCell = new HtmlTableCell();
                                //dTCell.Attributes.Add("class", "student_grid");
                                //this.dTCell.InnerHtml = "<div style=padding-left:10px;>" + dtFields.Rows[L]["FieldName"].ToString() + "</div>";
                                //dTCell.Attributes.Add("class", "darkblue_content");
                                //dTCell.Align = "left";
                                //dTCell.VAlign = "top";
                                // this.dTCell.InnerText = dtFields.Rows[L]["FieldName"].ToString() + " : ";
                                if (dtFields.Rows[L]["FieldName"].ToString() != "")
                                {
                                    dTCell.Align = "left";
                                    dTCell.VAlign = "top";
                                    //dTCell.Attributes.Add("class", "darkblue_content");
                                    this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + dtFields.Rows[L]["FieldName"].ToString() + "</div><div class=clear_m></div>";
                                    int FieldId = Convert.ToInt32(dtFields.Rows[L]["FieldId"]);
                                    //schoolcategory.FieldId = Convert.ToInt32(dtFields.Rows[L]["FieldId"]);
                                    // int addressfieldcount = StSuBL.CheckDefaultAddressFieldCount();
                                    // if (addressfieldcount > 0)
                                    // {
                                    DataTable dtaddressfields = schoolcategory.GetAddressFieldsByFieldIdStudentBusiness(SchoolID, FieldId, Session["MLUICulture"].ToString());
                                    //if (dtaddressfields ==null)
                                    //{
                                    //     string PrevSessionTable = "First";
                                    //     DataTable DataFromSession = (DataTable)Session[PrevSessionTable];
                                    //     dtaddressfields = DataFromSession;
                                    //}
                                    // DataRow dra = dtaddressfields.NewRow();
                                    // dra["FieldName"] = dtFields.Rows[tRows]["FieldName"].ToString();
                                    // dtaddressfields.Rows.InsertAt(dra, 0);
                                    int AddressTableRows;
                                    int AddressTableCells = 1;
                                    int AddressTableCellsmod = Convert.ToInt32(dtaddressfields.Rows.Count % AddressTableCells);
                                    int AddressTableCellsquotient = Convert.ToInt32(dtaddressfields.Rows.Count / AddressTableCells);
                                    if (AddressTableCellsmod != 0)
                                    {
                                        AddressTableCellsquotient = AddressTableCellsquotient + 1;
                                        int j = dtaddressfields.Rows.Count;
                                        DataRow dradd = dtaddressfields.NewRow();
                                        dtaddressfields.Rows.Add(dradd);
                                    }
                                    for (AddressTableRows = 0; AddressTableRows < AddressTableCellsquotient; AddressTableRows++)
                                    {
                                        AddressTableRows = 0;
                                        if (dtaddressfields.Rows.Count > 0 || dtaddressfields.Rows.Count != 0)
                                        {
                                            this.dTAddRow = new HtmlTableRow();
                                            for (AddressTableCells = 0; AddressTableCells < 1; AddressTableCells++)
                                            {
                                                this.dTAddCell = new HtmlTableCell();
                                                this.dTAddCell1 = new HtmlTableCell();
                                                this.dTAddCell2 = new HtmlTableCell();
                                                //dTAddCell.Attributes.Add("class", "student_grid");
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldName"].ToString() != "")
                                                {
                                                    this.dTAddCell.InnerHtml = "<div class='blue_bold'>" + dtaddressfields.Rows[AddressTableRows]["FieldName"].ToString() + "</div>";
                                                    //dTCell.Align = "right";
                                                    this.dTAddCell1.InnerText = " : ";
                                                }
                                                dTAddCell.Align = "left";
                                                dTAddCell2.Align = "left";
                                                dTAddCell.VAlign = "top";
                                                dTAddCell1.VAlign = "top";
                                                dTAddCell2.VAlign = "top";
                                                dTAddCell.Attributes.Add("class", "width45");

                                                //--------------------------------------------------------------


                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "1")
                                                {
                                                    TextBox txt = new TextBox();
                                                    HiddenField hdnFieldAddr = new HiddenField();
                                                    txt.ID = "txt" + InitialFieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();
                                                    txt.CssClass = "textbox2";
                                                    this.dTAddCell2.Controls.Add(txt);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "2")
                                                {
                                                    CheckBoxList chk = new CheckBoxList();
                                                    HiddenField hdnFieldAddr = new HiddenField();
                                                    chk.ID = "chk" + InitialFieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();
                                                    chk.Items.Add("Same as Student's Home Address");
                                                    chk.RepeatDirection = RepeatDirection.Horizontal;
                                                    this.dTAddCell2.Controls.Add(chk);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "3")
                                                {
                                                    RadioButtonList rdb = new RadioButtonList();
                                                    HiddenField hdnFieldAddr = new HiddenField();
                                                    rdb.ID = "rdb" + InitialFieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();
                                                    rdb.RepeatDirection = RepeatDirection.Horizontal;
                                                    this.dTAddCell2.Controls.Add(rdb);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "4")
                                                {
                                                    DropDownList ddl = new DropDownList();
                                                    HiddenField hdnFieldAddr = new HiddenField();
                                                    ddl.ID = "ddl" + InitialFieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();
                                                    ddl.CssClass = "dropdown2";
                                                    if (dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "4" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "13" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "24" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "40")
                                                    {
                                                        //categoryfields.populateState(ref ddl);
                                                        StuListCont.populateState(ref ddl);
                                                    }
                                                    if (dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "15" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "31")
                                                    {
                                                        //schoolcategory.PopulateContactRelationship(ref ddl);
                                                        StuListCont.PopulateContactRelationship(ref ddl);
                                                    }
                                                    this.dTAddCell2.Controls.Add(ddl);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "5")
                                                {
                                                    Label lbl = new Label();
                                                    HiddenField hdnFieldAddr = new HiddenField();
                                                    lbl.ID = "lbl" + InitialFieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();
                                                    this.dTAddCell2.Controls.Add(lbl);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                //*******************28/04/2010*******************
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "6")
                                                {
                                                    HiddenField hdnFieldAddr = new HiddenField();
                                                    hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString();
                                                    Control control = new Control();
                                                    control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                                                    control.ID = "uc" + InitialFieldId;
                                                    this.dTAddCell2.Controls.Add(control);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                //************************************************                
                                                this.dTAddRow.Controls.Add(dTAddCell);
                                                this.dTAddRow.Controls.Add(dTAddCell1);
                                                this.dTAddRow.Controls.Add(dTAddCell2);
                                                dtaddressfields.Rows.RemoveAt(0);
                                                InitialFieldId++;
                                            }
                                            AddressTableRows = 0;
                                            dTAdd.Controls.Add(dTAddRow);
                                            //dTable.Controls.Add(dTRow);
                                        }
                                        else
                                        {
                                            break;
                                        }
                                        // FieldId++;
                                    }
                                    this.dTCell.Controls.Add(dTAdd);
                                    // }
                                    dtFields.Rows.RemoveAt(0);
                                    //tRows = 0;
                                    this.dTRow.Controls.Add(this.dTCell);
                                }
                            }
                            this.dTable.Controls.Add(dTRow);
                        }
                        else
                        {
                            break;
                        }
                    }
                    string[] SessionTable = AddTableList.Split(';');
                    int SessionTableId = 1;
                    for (int i = 1; i < SessionTable.Length; i++)
                    {
                        this.dTRow = new HtmlTableRow();
                        for (tCells = 0; tCells < 2; tCells++)
                        {
                            string sessionTab = "Address" + SessionTableId.ToString();
                            DataTable myArrayDataFromSession = (DataTable)Session[sessionTab];
                            if (myArrayDataFromSession != null)
                            {
                                this.dTCell = new HtmlTableCell();
                                this.dTAdd = new HtmlTable();
                                //dTCell.Attributes.Add("class", "darkblue_content");
                                string origtext = "Additional Contact";
                                string trantext = DTL.Translate(origtext, "en", langto);
                                this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + trantext + "</div><div class=clear_m></div>";
                                int AddressTableRows = 0;
                                for (int m = 0; m < myArrayDataFromSession.Rows.Count; m++)
                                {
                                    this.dTAddRow = new HtmlTableRow();
                                    this.dTAddCell = new HtmlTableCell();
                                    this.dTAddCell1 = new HtmlTableCell();
                                    this.dTAddCell2 = new HtmlTableCell();
                                    this.dTAddCell.Align = "right";
                                    //dTAddCell.Attributes.Add("class", "student_grid");
                                    if (myArrayDataFromSession.Rows[m]["FieldName"].ToString() != "")
                                    {
                                        this.dTAddCell.InnerHtml = "<div class='blue_bold'>" + myArrayDataFromSession.Rows[m]["FieldName"].ToString() + "</div>";
                                        this.dTAddCell1.InnerText = " : ";
                                    }
                                    dTAddCell.Align = "left";
                                    dTAddCell2.Align = "left";
                                    dTAddCell.VAlign = "top";
                                    dTAddCell1.VAlign = "top";
                                    dTAddCell2.VAlign = "top";
                                    dTAddCell.Attributes.Add("class", "width45");
                                    if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "1")
                                    {
                                        TextBox txt = new TextBox();
                                        HiddenField hdnFieldAddr = new HiddenField();
                                        txt.CssClass = "textbox2";
                                        txt.ID = "txt" + InitialFieldId;
                                        hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                        hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                        this.dTAddCell2.Controls.Add(txt);
                                        this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                    }
                                    if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "2")
                                    {
                                        CheckBoxList chk = new CheckBoxList();
                                        HiddenField hdnFieldAddr = new HiddenField();
                                        chk.ID = "chk" + InitialFieldId;
                                        hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                        hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                        chk.Items.Add("Same as Student's Home Address");
                                        chk.RepeatDirection = RepeatDirection.Horizontal;
                                        this.dTAddCell2.Controls.Add(chk);
                                        this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                    }
                                    if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "3")
                                    {
                                        RadioButtonList rdb = new RadioButtonList();
                                        HiddenField hdnFieldAddr = new HiddenField();
                                        rdb.ID = "rdb" + InitialFieldId;
                                        hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                        hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                        rdb.RepeatDirection = RepeatDirection.Horizontal;
                                        this.dTAddCell2.Controls.Add(rdb);
                                        this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                    }
                                    if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "4")
                                    {
                                        DropDownList ddl = new DropDownList();
                                        HiddenField hdnFieldAddr = new HiddenField();
                                        ddl.ID = "ddl" + InitialFieldId;
                                        hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                        hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                        ddl.CssClass = "dropdown2";
                                        if (myArrayDataFromSession.Rows[m]["FieldId"].ToString() == "4")
                                        {
                                            //categoryfields.populateState(ref ddl);
                                            StuListCont.populateState(ref ddl);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldId"].ToString() == "1")
                                        {
                                            // schoolcategory.PopulateContactRelationship(ref ddl);
                                            StuListCont.PopulateContactRelationship(ref ddl);
                                        }
                                        this.dTAddCell2.Controls.Add(ddl);
                                        this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                    }
                                    if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "5")
                                    {
                                        Label lbl = new Label();
                                        HiddenField hdnFieldAddr = new HiddenField();
                                        lbl.ID = "lbl" + InitialFieldId;
                                        hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                        hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                        this.dTAddCell2.Controls.Add(lbl);
                                        this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                    }
                                    //*******************28/04/2010*******************
                                    if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "6")
                                    {
                                        HiddenField hdnFieldAddr = new HiddenField();
                                        hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                        hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                        Control control = new Control();
                                        control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                                        control.ID = "uc" + InitialFieldId;
                                        this.dTAddCell2.Controls.Add(control);
                                        this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                    }
                                    //************************************************
                                    this.dTAddRow.Controls.Add(dTAddCell);
                                    this.dTAddRow.Controls.Add(dTAddCell1);
                                    this.dTAddRow.Controls.Add(dTAddCell2);
                                    //myArrayDataFromSession.Rows.RemoveAt(0);
                                    InitialFieldId++;
                                    //}
                                    AddressTableRows = 0;
                                    dTAdd.Controls.Add(dTAddRow);
                                }
                                this.dTCell.Controls.Add(dTAdd);
                                this.dTRow.Controls.Add(this.dTCell);
                                this.dTable.Controls.Add(dTRow);
                            }
                            SessionTableId++;
                            // }
                        }
                    }
                    //***********
                    //int SchoolID = Convert.ToInt32(Session["SchoolID"]);

                    int HomeFieldId = 152;
                    //DataTable dtFields = schoolcategory.PopulateAdditionalField();
                    DataTable dtFields1 = schoolcategory.PopulateAdditionalFieldStudentBusiness(SchoolID, HomeFieldId, Session["MLUICulture"].ToString());
                    rptAdditionalList.DataSource = dtFields1;
                    rptAdditionalList.DataBind();

                    phAllFieldHolder.Controls.Add(dTable);
                }
            }
        }
        catch (Exception ex)
        {
            string EX = ex.ToString();
        }
    }   

    protected void ibtnAdd_Click(object sender, ImageClickEventArgs e)
    {

        PopulateAdditionalFields();

        ModalPopupExtender1.Enabled = true;
        ModalPopupExtender1.Show();


    }


    protected void PopulateAdditionalFields()
    {
        //StudentBL schoolcategory = new StudentBL();
        //EntryFormLayoutBL categoryfields = new EntryFormLayoutBL();
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        OpenSISWCFServiceStudentFormLayoutClient categoryfields = new OpenSISWCFServiceStudentFormLayoutClient();
        hdnInitialCatId.Value = hdnCatId.Value;
        int CatId = Convert.ToInt32(hdnCatId.Value);
        //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
        //schoolcategory.SchoolID = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);

        int SchoolID = Convert.ToInt32(Session["SchoolID"]);

        int HomeFieldId = 152;
        //DataTable dtFields = schoolcategory.PopulateAdditionalField();
        DataTable dtFields = schoolcategory.PopulateAdditionalFieldStudentBusiness(SchoolID, HomeFieldId, Session["MLUICulture"].ToString());
        rptAdditionalList.DataSource = dtFields;
        rptAdditionalList.DataBind();
        //this.dtAdditionalCont.CellPadding = 2;
        //this.dtAdditionalCont.CellSpacing = 0;
        //this.dtAdditionalCont.Border = 0;
        //this.dtAdditionalCont.Width = "100%";
        ////this.dtAdditionalCont.Attributes.Add("class", "darkblue_content");

        //int tRows;
        //int tCells = 1;
        //int tCellsmod = Convert.ToInt32(dtFields.Rows.Count % tCells);

        //int tCellsquotient = Convert.ToInt32(dtFields.Rows.Count / tCells);
        //if (tCellsmod != 0)
        //{
        //    tCellsquotient = tCellsquotient + 1;
        //    int j = dtFields.Rows.Count;

        //    DataRow dr = dtFields.NewRow();
        //    dtFields.Rows.Add(dr);

        //}
        //int FieldId = 200;
        ////this.dTAdditionalContRow = new HtmlTableRow();
        ////this.dTAdditionalContCell = new HtmlTableCell();
        ////this.dTAdditionalContCell.InnerHtml = "<div style=padding-left:20px>" + "Additional Contact" + "</div>";
        ////dTAdditionalContRow.Cells.Add(dTAdditionalContCell);
        ////dtAdditionalCont.Rows.Insert(0, dTAdditionalContRow);
        //for (tRows = 0; tRows < tCellsquotient; tRows++)
        //{
        //    tRows = 0;
        //    if (dtFields.Rows.Count > 0 || dtFields.Rows.Count != 0)
        //    {

        //        this.dTAdditionalContRow = new HtmlTableRow();
        //        for (tCells = 0; tCells < 1; tCells++)
        //        {

        //            this.dTAdditionalContCell = new HtmlTableCell();
        //            this.dTAdditionalContCell1 = new HtmlTableCell();
        //            this.dTAdditionalContCell2 = new HtmlTableCell();
        //            dTAdditionalContCell.Attributes.Add("class", "student_grid");
        //            if (dtFields.Rows[tRows]["FieldName"].ToString() != "")
        //            {
        //                this.dTAdditionalContCell.InnerHtml = "<div style=padding-left:20px>" + dtFields.Rows[tRows]["FieldName"].ToString() + "</div>";
        //                this.dTAdditionalContCell1.InnerText = ":";
        //            }
        //            dTAdditionalContCell.Align = "left";
        //            dTAdditionalContCell2.Align = "left";
        //            //if (dtFields.Rows[tRows]["FieldId"].ToString() != "")
        //            //{
        //            //    categoryfields.FieldId = Convert.ToInt32(dtFields.Rows[tRows]["FieldId"]);
        //            //}
        //            if (dtFields.Rows[tRows]["FieldType"].ToString() == "1")
        //            {
        //                TextBox txt = new TextBox();
        //                txt.CssClass = "textbox2";
        //                txt.ID = "txt" + FieldId;
        //                this.dTAdditionalContCell2.Controls.Add(txt);
        //            }
        //            if (dtFields.Rows[tRows]["FieldType"].ToString() == "2")
        //            {
        //                CheckBoxList chk = new CheckBoxList();
        //                chk.ID = "chk" + FieldId;
        //                chk.Items.Add("Same as Student's Home Address");
        //                chk.RepeatDirection = RepeatDirection.Horizontal;
        //                this.dTAdditionalContCell2.Controls.Add(chk);
        //            }
        //            if (dtFields.Rows[tRows]["FieldType"].ToString() == "3")
        //            {
        //                RadioButtonList rdb = new RadioButtonList();
        //                rdb.ID = "rdb" + FieldId;
        //                rdb.RepeatDirection = RepeatDirection.Horizontal;

        //                this.dTAdditionalContCell2.Controls.Add(rdb);
        //            }
        //            if (dtFields.Rows[tRows]["FieldType"].ToString() == "4")
        //            {
        //                DropDownList ddl = new DropDownList();
        //                ddl.ID = "ddl" + FieldId;
        //                ddl.CssClass = "dropdown2";
        //                if (dtFields.Rows[tRows]["FieldId"].ToString() == "4")
        //                {
        //                    //categoryfields.populateState(ref ddl);
        //                    StuListCont.populateState(ref ddl);
        //                }
        //                if (dtFields.Rows[tRows]["FieldId"].ToString() == "1")
        //                {
        //                    //schoolcategory.PopulateContactRelationship(ref ddl);
        //                    StuListCont.PopulateContactRelationship(ref ddl);
        //                }
        //                this.dTAdditionalContCell2.Controls.Add(ddl);
        //            }
        //            if (dtFields.Rows[tRows]["FieldType"].ToString() == "5")
        //            {
        //                Label lbl = new Label();
        //                lbl.ID = "lbl" + FieldId;
        //                // StudentBL stbl2 = new StudentBL();
        //                this.dTAdditionalContCell2.Controls.Add(lbl);
        //            }


        //            //************
        //            if (dtFields.Rows[tRows]["FieldType"].ToString() == "6")
        //            {
                        


                       
        //                Control control = new Control();
        //                control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
        //                control.ID = "uc" + FieldId;
        //                this.dTAdditionalContCell2.Controls.Add(control);
                      


        //            }


        //            this.dTAdditionalContRow.Controls.Add(dTAdditionalContCell);
        //            this.dTAdditionalContRow.Controls.Add(dTAdditionalContCell1);
        //            this.dTAdditionalContRow.Controls.Add(dTAdditionalContCell2);
        //            dtFields.Rows.RemoveAt(0);
        //            tRows = 0;
        //            FieldId++;
        //        }
        //        this.dtAdditionalCont.Controls.Add(dTAdditionalContRow);

        //    }
        //    else
        //    {
        //        break;
        //    }
        //    FieldId++;
        //}

        //AdditionalList.Controls.Add(dtAdditionalCont);
    }

    //*************
    protected void StoreMedicalInfoFieldDataIntoDatatable()
    {


        DataTable dtUserData = new DataTable();
        dtUserData.Columns.Add("Value");
        dtUserData.Columns.Add("FieldId");
        dtUserData.Columns.Add("FieldCatagory");

        for (int i = 0; i <= rptMedicalInfo.Items.Count - 1; i++)
        {
            DataRow dr = dtUserData.NewRow();
            TextBox txtfieldvalue = (TextBox)rptMedicalInfo.Items[i].FindControl("txt");
            HiddenField hdnFieldId = (HiddenField)rptMedicalInfo.Items[i].FindControl("hdnFieldId");
            if (txtfieldvalue != null)
            {
                dr[0] = txtfieldvalue.Text.ToString();
                dr[1] = hdnFieldId.Value.ToString();
            }
            DropDownList ddlfieldvalue = (DropDownList)rptMedicalInfo.Items[i].FindControl("ddl");
            if (ddlfieldvalue != null)
            {
                dr[0] = ddlfieldvalue.SelectedItem.Text.ToString();

            }

            dtUserData.Rows.Add(dr);
        }

        string SessionTableName = "MedicalInfo";
        Session.Add(SessionTableName, dtUserData);
    }

    public void StoreSchoolInfoFieldDataIntoDatatable()
    {
        //ddlFullYear = (DropDownList)Page.Master.FindControl("ddlFullYear");
        //string s = ddlFullYear.SelectedItem.Value;

        DataTable dtUserData = new DataTable();
        dtUserData.Columns.Add("Value");
        dtUserData.Columns.Add("FieldId");
        dtUserData.Columns.Add("Category");
        dtUserData.Columns.Add("Default_Custom");

        for (int i = 0; i <= rptrSchlInfo.Items.Count - 1; i++)
        {
            DataRow dr = dtUserData.NewRow();

            TextBox txtfieldvalue = (TextBox)rptrSchlInfo.Items[i].FindControl("txt");
            HiddenField hdnFieldId = (HiddenField)rptrSchlInfo.Items[i].FindControl("hdnFieldId");
            HiddenField hdnDefCus = (HiddenField)rptrSchlInfo.Items[i].FindControl("hdnDefCus");
            if (txtfieldvalue != null)
            {
                dr[0] = txtfieldvalue.Text.ToString();
                //dr[1] = hdnFieldId.Value.ToString();
                //dr[2] = hdnCatId.Value.ToString();
                //dr[3] = hdnDefCus.Value.ToString();
                //dtUserData.Rows.Add(dr);
            }
            DropDownList ddlfieldvalue = (DropDownList)rptrSchlInfo.Items[i].FindControl("ddl");
            if (ddlfieldvalue != null)
            {


                if (ddlfieldvalue.SelectedIndex != -1)
                {
                    dr[0] = ddlfieldvalue.SelectedItem.Value.ToString();

                }

            }
            RadioButtonList rdb = (RadioButtonList)rptrSchlInfo.Items[i].FindControl("rdb");
            if (rdb != null)
            {
                for (int r = 0; r < rdb.Items.Count; r++)
                {
                    if (rdb.Items[r].Selected)
                    {
                        dr[0] = rdb.SelectedItem.Value.ToString();
                        //dr[1] = hdnFieldId.Value.ToString();
                        //dr[2] = hdnCatId.Value.ToString();
                        //dr[3] = hdnDefCus.Value.ToString();
                        //dtUserData.Rows.Add(dr);
                    }

                }

            }

            DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrSchlInfo.Items[i].FindControl("uc");
            if (uc != null)
            {
                dr[0] = uc.Value.ToString();

            }
            dr[1] = hdnFieldId.Value.ToString();
            dr[2] = hdnCatId.Value.ToString();
            dr[3] = hdnDefCus.Value.ToString();
            dtUserData.Rows.Add(dr);

        }




        string SessionTableName = "SchoolInfo";
        Session.Add(SessionTableName, dtUserData);

    }

    protected void PopulateMedicalInfoFieldData()
    {
        try
        {

            string PrevSessionTable = "MedicalInfo";
            DataTable MedicalInfoDataFromSession = (DataTable)Session[PrevSessionTable];

            if (MedicalInfoDataFromSession != null)
            {
                int v = 0;


                for (int i = 0; i <= rptMedicalInfo.Items.Count - 1; i++)
                {

                    TextBox txtfieldvalue = (TextBox)rptMedicalInfo.Items[i].FindControl("txt");

                    if (txtfieldvalue != null)
                    {
                        txtfieldvalue.Text = MedicalInfoDataFromSession.Rows[v][0].ToString();
                    }

                    DropDownList ddlfieldvalue = (DropDownList)rptMedicalInfo.Items[i].FindControl("ddl");
                    if (ddlfieldvalue != null)
                    {


                    }
                    v++;

                }

            }


        }
        catch (Exception ex)
        {
            string Ex = ex.ToString();
        }

    }

    protected void PopulateVaccinationFieldData()
    {
        try
        {

            string PrevSessionTable = "Vaccination";
            DataTable VaccinationDataFromSession = (DataTable)Session[PrevSessionTable];

            if (VaccinationDataFromSession != null)
            {
                int v = 0;


                for (int i = 0; i <= rptrVaceField.Items.Count - 1; i++)
                {

                    TextBox txtfieldvalue = (TextBox)rptrVaceField.Items[i].FindControl("txt");

                    if (txtfieldvalue != null)
                    {
                        txtfieldvalue.Text = VaccinationDataFromSession.Rows[v][0].ToString();
                    }

                    DropDownList ddlfieldvalue = (DropDownList)rptrVaceField.Items[i].FindControl("ddl");
                    if (ddlfieldvalue != null)
                    {


                    }
                    v++;

                }

            }


        }
        catch (Exception ex)
        {
            string Ex = ex.ToString();
        }

    }

    protected void PopulateSchoolInfoFieldData()
    {
        try
        {

            string PrevSessionTable = "SchoolInfo";
            DataTable SchoolInfoDataFromSession = (DataTable)Session[PrevSessionTable];

            if (SchoolInfoDataFromSession != null)
            {
                int v = 0;


                for (int i = 0; i <= rptrSchlInfo.Items.Count - 1; i++)
                {
                    HiddenField hdnFieldId = (HiddenField)rptrSchlInfo.Items[i].FindControl("hdnFieldId");
                    TextBox txtfieldvalue = (TextBox)rptrSchlInfo.Items[i].FindControl("txt");

                    if (txtfieldvalue != null)
                    {
                        txtfieldvalue.Text = SchoolInfoDataFromSession.Rows[v][0].ToString();
                    }

                    DropDownList ddlfieldvalue = (DropDownList)rptrSchlInfo.Items[i].FindControl("ddl");
                    if (ddlfieldvalue != null)
                    {
                        ddlfieldvalue.Items.FindByValue(SchoolInfoDataFromSession.Rows[v][0].ToString()).Selected = true;
                    }
                    RadioButtonList rdb = (RadioButtonList)rptrSchlInfo.Items[i].FindControl("rdb");
                    if (rdb != null)
                    {
                        for (int r = 0; r < rdb.Items.Count; r++)
                        {
                            if (rdb.Items[r].Value == SchoolInfoDataFromSession.Rows[v][0].ToString())
                            {
                                rdb.Items[r].Selected = true;
                            }
                        }
                    }
                    DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrSchlInfo.Items[i].FindControl("uc");
                    if (uc != null)
                    {
                       
                        uc.Value = SchoolInfoDataFromSession.Rows[v][0].ToString();
                    }


                    v++;

                }

            }


        }
        catch (Exception ex)
        {
            //string Ex = ex.ToString();
            throw new Exception(ex.ToString());
        }

    }

    public void PopulateGiftValue()
    {



        DataTable SessiondtGift = (DataTable)Session["SpecialGiftForInsert"];
        if (SessiondtGift != null)
        {
            rptrGiftProg.DataSource = SessiondtGift;
            rptrGiftProg.DataBind();

        }


    }

    public void PopulateSpecialValue()
    {



        DataTable SessiondtSpecialEdu = (DataTable)Session["SpecialEduForInsert"];
        if (SessiondtSpecialEdu != null)
        {
            rptrSpecEdu.DataSource = SessiondtSpecialEdu;
            rptrSpecEdu.DataBind();

        }


    }
    //***************
    protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
    {
        try
        {

            StoreFieldDataIntoDatatable();
            //StoreMedicalInfoFieldDataIntoDatatable();

            //******06/05/2010********
             int Count = dTable.Rows.Count;

            for (int k = Count - 1; k >= 0; k--)
            {
                this.dTable.Rows.RemoveAt(k);
            }



            if (hdnCatId.Value.ToString() == "5")
            {

                StoreMedicalInfoFieldDataIntoDatatable();
                DataStoreProgramForVaccination();

            }

            if (hdnCatId.Value.ToString() == "4")
            {

                StoreSchoolInfoFieldDataIntoDatatable();


            }
            hdnCatId.Value = TreeView1.SelectedNode.Value.Split(",".ToCharArray())[0];



            //if (hdnCatId.Value.ToString() == "5")
            //{

            //
            //StoreVaccinationFieldDataIntoDatatable();

            //}
            PopulateInSelectedNodeChange();
           
            if (hdnCatId.Value.ToString() == "5")
            {

                PopulateMedicalInfoFieldData();
                //PopulateVaccinationFieldData();
                PopulateVccinationValue();

            }
            if (hdnCatId.Value.ToString() == "4")
            {

                PopulateSchoolInfoFieldData();


            }
            if (hdnCatId.Value.ToString() == "8")
            {

                PopulateGiftValue();
                PopulateSpecialValue();


            }
            PopulateFieldData();

        }
        catch (Exception x)
        {
            // string s = x.Message;
            throw new Exception(x.ToString());
        }
    }
    //**************
    protected void PopulateAddressFieldData()
    {
        try
        {
            
            string[] SessionTable = AddTableList.Split(';');
           
            string sessionTab = SessionTable[0].ToString();
            DataTable SessiondtAddress = (DataTable)Session[sessionTab];
           
            if (SessiondtAddress != null)
            {
                
                if (!SessiondtAddress.Columns.Contains("Value"))
                {
                    SessiondtAddress.Columns.Add("Value");

                }
                foreach (var C in panel_Popup.Controls)
                {

                    if (object.ReferenceEquals(C.GetType(), typeof(Repeater)))
                    {

                        for (int i = 0; i <= rptAdditionalList.Items.Count - 1; i++)
                        {
                            
                            TextBox txtfieldvalue = (TextBox)rptAdditionalList.Items[i].FindControl("txt");
                            DropDownList ddlfieldvalue = (DropDownList)rptAdditionalList.Items[i].FindControl("ddl");
                            RadioButtonList rdbfieldvalue = (RadioButtonList)rptAdditionalList.Items[i].FindControl("rdb");
                            CheckBoxList chk = (CheckBoxList)rptAdditionalList.Items[i].FindControl("chk");
                            HiddenField hdnFieldId = (HiddenField)rptAdditionalList.Items[i].FindControl("hdnFieldId");
                            if (txtfieldvalue != null)
                            {
                               
                               
                                SessiondtAddress.Rows[i]["Value"] = txtfieldvalue.Text.ToString();
                            }

                            //*********************01/05/2010**************
                            DatePicker.DatePicker uc = (DatePicker.DatePicker)rptAdditionalList.Items[i].FindControl("uc");
                            if (uc != null)
                            {

                            
                                SessiondtAddress.Rows[i]["Value"] = uc.Value.ToString();
                            }


                            if (ddlfieldvalue != null)
                            {


                                if (ddlfieldvalue.SelectedIndex != -1)
                                {
                                    
                                    SessiondtAddress.Rows[i]["Value"] = ddlfieldvalue.SelectedItem.Value.ToString();
                                }

                            }

                            if (rdbfieldvalue != null)
                            {
                                for (int r = 0; r < rdbfieldvalue.Items.Count; r++)
                                {
                                    if (rdbfieldvalue.Items[r].Selected)
                                    {
                                       
                                        SessiondtAddress.Rows[i]["Value"] = rdbfieldvalue.SelectedItem.Value.ToString();
                                    }

                                }

                            }
                            if (chk != null)
                              {
                                for (int j = 0; j < chk.Items.Count; j++)
                                {
                                    if (chk.Items[j].Selected)
                                    {
                                        
                                        SessiondtAddress.Rows[i]["Value"] = chk.SelectedItem.Value.ToString();
                                    }

                                }

                            }
                      
                            SessiondtAddress.AcceptChanges();
                        }
                    }
                        
                }
              
                
              

               
            }
           
          
        }
        catch (Exception ex)
        {
            //string Ex = ex.ToString();
            throw new Exception(ex.ToString());
        }

    }
    //**********
    protected void PopulateFieldData()
    {
        try
        {

            string PrevSessionTable = hdnCatId.Value.ToString();
            DataTable myArrayDataFromSession = (DataTable)Session[PrevSessionTable];

            if (myArrayDataFromSession != null)
            {

                foreach (var C in phAllFieldHolder.Controls)
                {

                    if (object.ReferenceEquals(C.GetType(), typeof(HtmlTable)))
                    {
                        HtmlTable dtFieldHolder = ((HtmlTable)C);

                        int TableRow = 0;
                        foreach (Control row in dtFieldHolder.Controls)
                        {

                            int TableCell = 0;

                            foreach (Control cell in row.Controls)
                            {

                                foreach (Control Con in cell.Controls)
                                {
                                    if (object.ReferenceEquals(Con.GetType(), typeof(TextBox)))
                                    {
                                        TextBox txtUserField = ((TextBox)Con);
                                        txtUserField.Text = myArrayDataFromSession.Rows[TableRow][TableCell].ToString();
                                        TableCell = TableCell + 3;
                                    }


                                    if (Con.GetType().Name.ToLower() == "datepicker_ascx")
                                    {
                                        DatePicker.DatePicker uc = ((DatePicker.DatePicker)Con);
                                        uc.Value = myArrayDataFromSession.Rows[TableRow][TableCell].ToString();
                                        TableCell = TableCell + 3;
                                    }



                                    if (object.ReferenceEquals(Con.GetType(), typeof(DropDownList)))
                                    {
                                        DropDownList ddlUserField = ((DropDownList)Con);
                                        if (myArrayDataFromSession.Rows[TableRow][TableCell].ToString() != "")
                                        {
                                            ddlUserField.Items.FindByValue(myArrayDataFromSession.Rows[TableRow][TableCell].ToString()).Selected = true;
                                        }

                                        TableCell = TableCell + 3;
                                    }
                                    if (object.ReferenceEquals(Con.GetType(), typeof(CheckBoxList)))
                                    {
                                        CheckBoxList ChkUserField = ((CheckBoxList)Con);
                                        for (int i = 0; i < ChkUserField.Items.Count; i++)
                                        {
                                            if (ChkUserField.Items[i].Value == myArrayDataFromSession.Rows[TableRow][TableCell].ToString())
                                            {
                                                ChkUserField.Items[i].Selected = true;
                                            }
                                        }
                                        TableCell = TableCell + 3;
                                    }
                                    if (object.ReferenceEquals(Con.GetType(), typeof(RadioButtonList)))
                                    {
                                        RadioButtonList rdoUserField = ((RadioButtonList)Con);
                                        for (int i = 0; i < rdoUserField.Items.Count; i++)
                                        {
                                            if (rdoUserField.Items[i].Value == myArrayDataFromSession.Rows[TableRow][TableCell].ToString())
                                            {
                                                rdoUserField.Items[i].Selected = true;
                                            }
                                        }
                                        TableCell = TableCell + 3;
                                    }
                                    if (object.ReferenceEquals(Con.GetType(), typeof(Label)))
                                    {

                                        TableCell = TableCell + 3;
                                    }
                                    if (object.ReferenceEquals(Con.GetType(), typeof(HtmlTable)))
                                    {
                                        HtmlTable dtAddFieldHolder = ((HtmlTable)Con);

                                        foreach (Control Addrow in dtAddFieldHolder.Controls)
                                        {
                                            int AddCellCount = 0;

                                            foreach (Control Addcell in Addrow.Controls)
                                            {
                                                foreach (Control AddCon in Addcell.Controls)
                                                {
                                                    if (TableRow <= myArrayDataFromSession.Rows.Count - 1)
                                                    {
                                                        if (object.ReferenceEquals(AddCon.GetType(), typeof(TextBox)))
                                                        {
                                                            TextBox txtUserField = ((TextBox)AddCon);
                                                            txtUserField.Text = myArrayDataFromSession.Rows[TableRow][AddCellCount++].ToString();
                                                        }
                                                        if (object.ReferenceEquals(AddCon.GetType(), typeof(DropDownList)))
                                                        {
                                                            DropDownList ddlUserFieldAdd = ((DropDownList)AddCon);
                                                            if (myArrayDataFromSession.Rows[TableRow][AddCellCount].ToString() != "")
                                                            {
                                                                ddlUserFieldAdd.Items.FindByValue(myArrayDataFromSession.Rows[TableRow][AddCellCount++].ToString()).Selected = true;
                                                            }

                                                        }
                                                    }


                                                }

                                            }

                                            TableRow++;
                                        }

                                    }

                                }

                            }
                            TableRow++;
                        }
                    }
                }
            }


        }
        catch (Exception ex)
        {
            //string Ex = ex.ToString();
            throw new Exception(ex.ToString());
        }

    }

    //************************
    protected void StoreFieldDataIntoDatatable()
    {
        //try
        //{


        DataTable dtUserData = new DataTable();
        dtUserData.Columns.Add("Value");
        dtUserData.Columns.Add("FieldId");
        dtUserData.Columns.Add("FieldCatagory");
        dtUserData.Columns.Add("Value1");
        dtUserData.Columns.Add("FieldId1");
        dtUserData.Columns.Add("FieldCatagory1");
        int set = -3;

        foreach (var C in phAllFieldHolder.Controls)
        {
            if (object.ReferenceEquals(C.GetType(), typeof(HtmlTable)))
            {
                HtmlTable dtFieldHolder = ((HtmlTable)C);

                foreach (Control row in dtFieldHolder.Controls)
                {
                    int CellCount = 0;
                    DataRow dr = dtUserData.NewRow();
                    foreach (Control cell in row.Controls)
                    {

                        foreach (Control Con in cell.Controls)
                        {
                            if (object.ReferenceEquals(Con.GetType(), typeof(TextBox)))
                            {
                                TextBox txtUserField = ((TextBox)Con);
                                dr[CellCount++] = txtUserField.Text.ToString();

                            }

                            //***************28/04/2010
                            //if (object.ReferenceEquals(Con.GetType(), typeof(DatePicker.DatePicker)))
                            //{
                            //    DatePicker.DatePicker uc = ((DatePicker.DatePicker)Con);
                            //    dr[CellCount++] = uc.Value.ToString();
                               

                            //}

                            if (Con.GetType().Name.ToLower() == "datepicker_ascx")
                            {
                                DatePicker.DatePicker uc = ((DatePicker.DatePicker)Con);
                                dr[CellCount++] = uc.Value.ToString();
                            }

                            if (object.ReferenceEquals(Con.GetType(), typeof(DropDownList)))
                            {
                                DropDownList ddlUserField = ((DropDownList)Con);

                                if (ddlUserField.SelectedItem != null)
                                {
                                    dr[CellCount] = ddlUserField.SelectedItem.Value.ToString();
                                }
                                CellCount = CellCount + 1;

                            }
                            if (object.ReferenceEquals(Con.GetType(), typeof(CheckBoxList)))
                            {

                                CheckBoxList ChkUserField = ((CheckBoxList)Con);

                                for (int i = 0; i < ChkUserField.Items.Count; i++)
                                {
                                    if (ChkUserField.Items[i].Selected)
                                    {
                                        dr[CellCount] = ChkUserField.SelectedItem.Value.ToString();
                                    }
                                }
                                CellCount = CellCount + 1;
                            }
                            if (object.ReferenceEquals(Con.GetType(), typeof(RadioButtonList)))
                            {
                                RadioButtonList rdoUserField = ((RadioButtonList)Con);
                                for (int i = 0; i < rdoUserField.Items.Count; i++)
                                {
                                    if (rdoUserField.Items[i].Selected)
                                    {
                                        dr[CellCount] = rdoUserField.SelectedItem.Value.ToString();
                                    }
                                }
                                CellCount = CellCount + 1;
                            }
                            if (object.ReferenceEquals(Con.GetType(), typeof(Label)))
                            {

                                CellCount++;

                            }
                            if (object.ReferenceEquals(Con.GetType(), typeof(HiddenField)))
                            {
                                HiddenField FieldId = ((HiddenField)Con);
                                dr[CellCount++] = FieldId.Value.Split("_".ToCharArray())[0];
                                dr[CellCount++] = FieldId.Value.Split("_".ToCharArray())[1];
                            }
                            if (object.ReferenceEquals(Con.GetType(), typeof(HtmlTable)))
                            {


                                HtmlTable dtAddFieldHolder = ((HtmlTable)Con);

                                foreach (Control Addrow in dtAddFieldHolder.Controls)
                                {
                                    int AddCellCount = 0;

                                    DataRow Adddr = dtUserData.NewRow();


                                    foreach (Control Addcell in Addrow.Controls)
                                    {
                                        foreach (Control AddCon in Addcell.Controls)
                                        {
                                            if (object.ReferenceEquals(AddCon.GetType(), typeof(TextBox)))
                                            {
                                                TextBox txtUserField = ((TextBox)AddCon);
                                                Adddr[AddCellCount++] = txtUserField.Text.ToString();
                                            }

                                            //**********29/04/2010****************

                                            if (Con.GetType().Name.ToLower() == "datepicker_ascx")
                                            {
                                                DatePicker.DatePicker uc = ((DatePicker.DatePicker)Con);
                                                Adddr[AddCellCount++] = uc.Value.ToString();
                                            }


                                            if (object.ReferenceEquals(AddCon.GetType(), typeof(DropDownList)))
                                            {
                                                DropDownList ddlUserField = ((DropDownList)AddCon);
                                                if (ddlUserField.SelectedItem != null)
                                                {
                                                    Adddr[AddCellCount] = ddlUserField.SelectedItem.Value.ToString();
                                                }
                                                AddCellCount = AddCellCount + 1;
                                            }
                                            if (object.ReferenceEquals(AddCon.GetType(), typeof(HiddenField)))
                                            {
                                                HiddenField hdnFieldAddr = ((HiddenField)AddCon);
                                                HiddenField hdnDefFieldId = ((HiddenField)AddCon);
                                                Adddr[AddCellCount++] = hdnFieldAddr.Value.Split("_".ToCharArray())[0];
                                                Adddr[AddCellCount++] = hdnFieldAddr.Value.Split("_".ToCharArray())[1];
                                                Adddr[3] = set;
                                                if (set <= 0)
                                                {
                                                    if (hdnFieldAddr.Value.Split("_".ToCharArray()).Length==3)
                                                    {
                                                   
                                                    if (hdnFieldAddr.Value.Split("_".ToCharArray())[2] != "")
                                                    {
                                                        Adddr[4] = hdnFieldAddr.Value.Split("_".ToCharArray())[2];
                                                    }
                                                    }
                                                }

                                            }
                                        }
                                    }
                                    dtUserData.Rows.Add(Adddr);
                                }

                                set++;
                            }

                        }

                    }
                    dtUserData.Rows.Add(dr);
                }
            }
        }

        string SessionTableName = hdnCatId.Value.ToString();
        Session.Add(SessionTableName, dtUserData);


        //}
        //catch (Exception ex)
        //    {
        //        string EX = ex.ToString();
        //    }



    }


    protected void PopulateInSelectedNodeChange()
    {
        //EntryFormLayoutBL categoryfields = new EntryFormLayoutBL();
        ////try
        ////{
        //StudentBL schoolcategory = new StudentBL();
        //StudentSetupBL StSuBL = new StudentSetupBL();
        OpenSISWCFServiceStudentFormLayoutClient categoryfields = new OpenSISWCFServiceStudentFormLayoutClient();

        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        OpenSISWCFServiceStudentSetupClient StSuBL = new OpenSISWCFServiceStudentSetupClient();
        try
        {
            foreach (TreeNode tn in TreeView1.Nodes)
            {
                string t = tn.Value.Split(",".ToCharArray())[0];
                if (t == hdnCatId.Value.ToString())
                {

                    tn.Selected = true;

                }

            }
            hdnCatId.Value = TreeView1.SelectedNode.Value.Split(",".ToCharArray())[0];
            string CatName = TreeView1.SelectedNode.Text.ToString();

            hdnInitialCatId.Value = hdnCatId.Value;
            int Treepos = Convert.ToInt32(TreeView1.SelectedNode.Value.Split(",".ToCharArray())[1]);
            int CatId = Convert.ToInt32(hdnCatId.Value);
            //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);
            //*********06/05/2010******
          

            DataTable dt = schoolcategory.GetFieldsByCategoryStudentBusiness(SchoolID, CatId, Session["MLUICulture"].ToString());
            ///phAllFieldHolder.Controls.Clear();
            ibtnAdd.Visible = true;
            if (hdnCatId.Value.ToString() != "1")
            {
                divPhotoUpload.Style.Add("Display", "none");
                divOuter.Style.Add("Display", "none");
            }
            else if (hdnCatId.Value.ToString() == "1")
            {
                divPhotoUpload.Style.Add("Display", "block");
                divOuter.Style.Add("Display", "block");

            }

            int FieldId = 0;
            if (hdnCatId.Value.ToString() == "3")
            {
                //try
                //{
                tblProgram.Visible = false;
                tblSchEnrInfo.Visible = false;
                TMInfo.Visible = false;
                int Count = dTable.Rows.Count;

                for (int k = Count - 1; k >= 0; k--)
                {

                    this.dTable.Rows.RemoveAt(k);

                }

                hdnCatId.Value = hdnInitialCatId.Value;
                //DataTable dtFields = schoolcategory.GetFieldsByCategory();
                DataTable dtFields = schoolcategory.GetFieldsByCategoryStudentBusiness(SchoolID, CatId, Session["MLUICulture"].ToString());


                this.dTable.CellPadding = 2;
                this.dTable.CellSpacing = 0;
                this.dTable.Border = 0;
                this.dTable.Width = "100%";

                this.dTable.Attributes.Remove("class");
                string[] SessionTable = AddTableList.Split(';');

                int tRows;
                int tCells = 2;
                int tCellsmod = Convert.ToInt32(dtFields.Rows.Count % tCells);

                int tCellsquotient = Convert.ToInt32(dtFields.Rows.Count / tCells);
                if (tCellsmod != 0)
                {
                    tCellsquotient = tCellsquotient + 1;
                    DataRow dr = dtFields.NewRow();
                    dtFields.Rows.Add(dr);

                }



                for (tRows = 0; tRows < tCellsquotient; tRows++)
                {
                    int L = 0;

                    if (dtFields.Rows.Count > 0 || dtFields.Rows.Count != 0)
                    {

                        this.dTRow = new HtmlTableRow();

                        for (tCells = 0; tCells < 2; tCells++)
                        {
                            this.dTCell = new HtmlTableCell();

                            this.dTCell2 = new HtmlTableCell();
                            dTCell2.Attributes.Add("class", "bevel_verline");


                            this.dTAdd = new HtmlTable();
                            this.dTAdd.CellPadding = 2;
                            this.dTAdd.CellSpacing = 0;
                            this.dTAdd.Border = 0;
                            this.dTAdd.Width = "100%";

                            DataTable dtaddressfields = null;
                            if (dtFields.Rows[L]["FieldName"].ToString() != "")
                            {
                                dTCell.Align = "left";
                                dTCell.VAlign = "top";

                                //dTCell.Attributes.Add("class", "darkblue_content");
                                this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + dtFields.Rows[L]["FieldName"].ToString() + "</div><div class=clear_m></div>";
                                //StSuBL.FieldId = Convert.ToInt32(dtFields.Rows[L]["FieldId"]);
                                int FieldIdforpop = Convert.ToInt32(dtFields.Rows[L]["FieldId"]);
                                //schoolcategory.FieldId = Convert.ToInt32(dtFields.Rows[L]["FieldId"]);
                                //dtaddressfields = schoolcategory.GetAddressFieldsByFieldId();
                                dtaddressfields = schoolcategory.GetAddressFieldsByFieldIdStudentBusiness(SchoolID, FieldIdforpop, Session["MLUICulture"].ToString());




                                int AddressTableRows;
                                int AddressTableCells = 1;
                                int AddressTableCellsmod = Convert.ToInt32(dtaddressfields.Rows.Count % AddressTableCells);

                                int AddressTableCellsquotient = Convert.ToInt32(dtaddressfields.Rows.Count / AddressTableCells);
                                if (AddressTableCellsmod != 0)
                                {
                                    AddressTableCellsquotient = AddressTableCellsquotient + 1;
                                    int j = dtaddressfields.Rows.Count;

                                    DataRow dradd = dtaddressfields.NewRow();
                                    dtaddressfields.Rows.Add(dradd);

                                }


                                for (AddressTableRows = 0; AddressTableRows < AddressTableCellsquotient; AddressTableRows++)
                                {
                                    AddressTableRows = 0;
                                    if (dtaddressfields.Rows.Count > 0 || dtaddressfields.Rows.Count != 0)
                                    {

                                        this.dTAddRow = new HtmlTableRow();
                                        for (AddressTableCells = 0; AddressTableCells < 1; AddressTableCells++)
                                        {

                                            this.dTAddCell = new HtmlTableCell();
                                            this.dTAddCell1 = new HtmlTableCell();
                                            this.dTAddCell2 = new HtmlTableCell();
                                            this.dTAddCell.Align = "right";
                                            dTAddCell.Attributes.Add("class", "student_grid");

                                            this.dTAddCell.InnerHtml = "<div class='blue_bold'>" + dtaddressfields.Rows[AddressTableRows]["FieldName"].ToString() + "</div>";
                                            this.dTAddCell1.InnerText = " : ";
                                            dTAddCell.Align = "left";
                                            dTAddCell2.Align = "left";
                                            dTAddCell.VAlign = "top";
                                            dTAddCell1.VAlign = "top";
                                            dTAddCell2.VAlign = "top";
                                            dTAddCell.Attributes.Add("class", "width45");

                                            if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "1")
                                            {
                                                TextBox txt = new TextBox();
                                                HiddenField hdnFieldAddr = new HiddenField();

                                                txt.CssClass = "textbox2";
                                                txt.ID = "txt" + FieldId;
                                                hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                                hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                                this.dTAddCell2.Controls.Add(txt);
                                                this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                            }
                                            if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "2")
                                            {
                                                CheckBoxList chk = new CheckBoxList();
                                                HiddenField hdnFieldAddr = new HiddenField();

                                                chk.ID = "chk" + FieldId;
                                                hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                                hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                                chk.RepeatDirection = RepeatDirection.Horizontal;
                                                this.dTAddCell2.Controls.Add(chk);
                                                this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                            }
                                            if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "3")
                                            {
                                                RadioButtonList rdb = new RadioButtonList();
                                                HiddenField hdnFieldAddr = new HiddenField();

                                                rdb.ID = "rdb" + FieldId;
                                                hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                                hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                                rdb.RepeatDirection = RepeatDirection.Horizontal;
                                                this.dTAddCell2.Controls.Add(rdb);
                                                this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                            }
                                            if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "4")
                                            {
                                                DropDownList ddl = new DropDownList();
                                                HiddenField hdnFieldAddr = new HiddenField();

                                                ddl.ID = "ddl" + FieldId;
                                                hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                                hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                                ddl.CssClass = "dropdown2";
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "4" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "13" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "24" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "40")
                                                {
                                                    // categoryfields.populateState(ref ddl);
                                                    StuListCont.populateState(ref ddl);
                                                }
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "15" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "31")
                                                {
                                                    // schoolcategory.PopulateContactRelationship(ref ddl);
                                                    StuListCont.PopulateContactRelationship(ref ddl);
                                                }
                                                this.dTAddCell2.Controls.Add(ddl);
                                                this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                            }
                                            if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "5")
                                            {
                                                Label lbl = new Label();
                                                HiddenField hdnFieldAddr = new HiddenField();

                                                lbl.ID = "lbl" + FieldId;
                                                hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                                
                                                hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                                this.dTAddCell2.Controls.Add(lbl);
                                                this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                            }

                                            //*******************28/04/2010*******************
                                            if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "6")
                                            {
                                                HiddenField hdnFieldAddr = new HiddenField();
                                                hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                                hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString()+"_"+dtFields.Rows[L]["FieldId"].ToString();
                                                Control control = new Control();
                                                control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                                                control.ID = "uc" + FieldId;
                                                
                                                this.dTAddCell2.Controls.Add(control);
                                                this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                            }
                                            //************************************************

                                            this.dTAddRow.Controls.Add(dTAddCell);
                                            this.dTAddRow.Controls.Add(dTAddCell1);
                                            this.dTAddRow.Controls.Add(dTAddCell2);
                                            dtaddressfields.Rows.RemoveAt(0);
                                            FieldId++;

                                        }

                                        AddressTableRows = 0;
                                        dTAdd.Controls.Add(dTAddRow);

                                    }
                                    else
                                    {
                                        break;
                                    }


                                }
                                this.dTCell.Controls.Add(dTAdd);




                                dtFields.Rows.RemoveAt(0);
                                this.dTRow.Controls.Add(this.dTCell);
                                if (tCells == 0)
                                {
                                    this.dTRow.Controls.Add(this.dTCell2);
                                }

                            }


                        }

                        this.dTable.Controls.Add(dTRow);
                    }
                    else
                    {
                        break;
                    }

                }



                int SessionTableId = 1;
                for (int i = 1; i < SessionTable.Length; i++)
                {


                    this.dTRow = new HtmlTableRow();

                    for (tCells = 0; tCells < 2; tCells++)
                    {
                        string sessionTab = "Address" + SessionTableId.ToString();
                        DataTable myArrayDataFromSession = (DataTable)Session[sessionTab];
                        if (myArrayDataFromSession != null)
                        {
                            this.dTCell = new HtmlTableCell();
                            this.dTCell2 = new HtmlTableCell();
                            dTCell2.Attributes.Add("class", "bevel_verline");

                            this.dTAdd = new HtmlTable();
                            this.dTAdd.CellPadding = 2;
                            this.dTAdd.CellSpacing = 0;
                            this.dTAdd.Border = 0;
                            this.dTAdd.Width = "100%";
                            //dTCell.Attributes.Add("class", "darkblue_content");

                            string origtext = "Additional Contact";
                            string trantext = DTL.Translate(origtext, "en", langto);


                            //this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + "Additional Contact" + "</div><div class=clear_m></div>";
                            this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + trantext + "</div><div class=clear_m></div>";

                            int AddressTableRows = 0;
                            for (int m = 0; m < myArrayDataFromSession.Rows.Count; m++)
                            {

                                this.dTAddRow = new HtmlTableRow();

                                this.dTAddCell = new HtmlTableCell();
                                this.dTAddCell1 = new HtmlTableCell();
                                this.dTAddCell2 = new HtmlTableCell();
                                this.dTAddCell.Align = "right";
                                dTAddCell.Attributes.Add("class", "student_grid");
                                if (myArrayDataFromSession.Rows[m]["FieldName"].ToString() != "")
                                {
                                    this.dTAddCell.InnerHtml = "<div class='blue_bold'>" + myArrayDataFromSession.Rows[m]["FieldName"].ToString() + "</div>";
                                    this.dTAddCell1.InnerText = " : ";
                                }
                                dTAddCell.Align = "left";
                                dTAddCell2.Align = "left";
                                dTAddCell.VAlign = "top";
                                dTAddCell1.VAlign = "top";
                                dTAddCell2.VAlign = "top";
                                dTAddCell.Attributes.Add("class", "width45");

                                if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "1")
                                {
                                    TextBox txt = new TextBox();
                                    HiddenField hdnFieldAddr = new HiddenField();
                                    txt.CssClass = "textbox2";
                                    txt.ID = "txt" + FieldId;
                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                    hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();

                                    //**********
                                    txt.Text = myArrayDataFromSession.Rows[m]["Value"].ToString();

                                    this.dTAddCell2.Controls.Add(txt);
                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                }
                                if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "2")
                                {
                                    CheckBoxList chk = new CheckBoxList();
                                    HiddenField hdnFieldAddr = new HiddenField();
                                    chk.ID = "chk" + FieldId;
                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                    hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                    chk.Items.Add("Same as Student's Home Address");
                                    chk.RepeatDirection = RepeatDirection.Horizontal;

                                    for (int k = 0; k < chk.Items.Count; k++)
                                    {
                                        if (chk.Items[k].Value == myArrayDataFromSession.Rows[m]["Value"].ToString())
                                        {
                                            chk.Items[k].Selected = true;
                                        }
                                    }


                                    this.dTAddCell2.Controls.Add(chk);
                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                }
                                if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "3")
                                {
                                    RadioButtonList rdb = new RadioButtonList();
                                    HiddenField hdnFieldAddr = new HiddenField();
                                    rdb.ID = "rdb" + FieldId;
                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                    hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                    rdb.RepeatDirection = RepeatDirection.Horizontal;
                                    this.dTAddCell2.Controls.Add(rdb);
                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                }
                                if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "4")
                                {
                                    DropDownList ddl = new DropDownList();
                                    HiddenField hdnFieldAddr = new HiddenField();
                                    ddl.ID = "ddl" + FieldId;
                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                    hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                    ddl.CssClass = "dropdown2";
                                    if (myArrayDataFromSession.Rows[m]["FieldId"].ToString() == "4")
                                    {
                                        // categoryfields.populateState(ref ddl);
                                        StuListCont.populateState(ref ddl);
                                        ddl.Items.FindByValue(myArrayDataFromSession.Rows[m]["Value"].ToString()).Selected = true;
                                    }
                                    if (myArrayDataFromSession.Rows[m]["FieldId"].ToString() == "1")
                                    {
                                        // schoolcategory.PopulateContactRelationship(ref ddl);
                                        StuListCont.PopulateContactRelationship(ref ddl);
                                        ddl.Items.FindByValue(myArrayDataFromSession.Rows[m]["Value"].ToString()).Selected = true;
                                    }
                                    this.dTAddCell2.Controls.Add(ddl);
                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                }
                                if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "5")
                                {
                                    Label lbl = new Label();
                                    HiddenField hdnFieldAddr = new HiddenField();
                                    lbl.ID = "lbl" + FieldId;
                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                    hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                    this.dTAddCell2.Controls.Add(lbl);
                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                }

                                //*******************28/04/2010*******************
                                if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "6")
                                {
                                    HiddenField hdnFieldAddr = new HiddenField();
                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                    hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                    Control control = new Control();
                                    control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                                    control.ID = "uc" + FieldId;
                                    
                                    this.dTAddCell2.Controls.Add(control);
                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                }
                                //************************************************


                                this.dTAddRow.Controls.Add(dTAddCell);
                                this.dTAddRow.Controls.Add(dTAddCell1);
                                this.dTAddRow.Controls.Add(dTAddCell2);
                                // myArrayDataFromSession.Rows.RemoveAt(0);
                                FieldId++;

                                // }

                                AddressTableRows = 0;
                                dTAdd.Controls.Add(dTAddRow);

                            }


                            this.dTCell.Controls.Add(dTAdd);
                            this.dTRow.Controls.Add(this.dTCell);
                            if (tCells == 0)
                            {
                                this.dTRow.Controls.Add(this.dTCell2);
                            }

                            this.dTable.Controls.Add(dTRow);


                        }

                        SessionTableId++;
                        // }
                    }

                }



                phAllFieldHolder.Controls.Add(dTable);

                //}
                //catch
                //{

                //}
            }

            else
            {
                tblProgram.Visible = false;
                btnImmuAdd.Visible = false;
                ibtnAlertAdd.Visible = false;
                ibtnNursevisitAdd.Visible = false;
                GVImmunization.Visible = false;
                GVMedicalAlert.Visible = false;
                GVNurseVisitRec.Visible = false;
                ibtnVace.Visible = false;
                rptrVaceField.Visible = false;
                rptMedicalInfo.Visible = false;
                TMInfo.Visible = false;

                tblSchEnrInfo.Visible = false;
                rptrSchlInfo.Visible = false;
                gvEnrInfo.Visible = false;

                if (hdnCatId.Value.ToString() != "5")
                {
                    if (hdnCatId.Value.ToString() != "4")
                    {
                        if (hdnCatId.Value.ToString() != "8")
                        {

                            int Count = dTable.Rows.Count;

                            for (int k = Count - 1; k >= 0; k--)
                            {

                                this.dTable.Rows.RemoveAt(k);

                            }


                            this.dTable.CellPadding = 2;
                            this.dTable.CellSpacing = 0;
                            this.dTable.Border = 0;
                            this.dTable.Width = "100%";
                            this.dTable.Align = "center";
                            //this.dTable.Attributes.Add("class", "darkblue_content");

                            int tRows;
                            int tCells = 2;
                            int tCellsmod = Convert.ToInt32(dt.Rows.Count % tCells);

                            int tCellsquotient = Convert.ToInt32(dt.Rows.Count / tCells);
                            if (tCellsmod != 0)
                            {
                                tCellsquotient = tCellsquotient + 1;
                                int j = dt.Rows.Count;

                                DataRow dr = dt.NewRow();
                                dt.Rows.Add(dr);

                            }
                            ibtnAdd.Visible = false;

                            this.dTRow = new HtmlTableRow();
                            this.dTCell = new HtmlTableCell();
                            this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + CatName.ToString() + "</div>";
                            this.dTCell.ColSpan = 6;
                            this.dTRow.Cells.Add(dTCell);
                            this.dTable.Rows.Insert(0, dTRow);

                            for (tRows = 0; tRows < tCellsquotient; tRows++)
                            {
                                tRows = 0;
                                if (dt.Rows.Count > 0 || dt.Rows.Count != 0)
                                {

                                    this.dTRow = new HtmlTableRow();
                                    for (tCells = 0; tCells < 2; tCells++)
                                    {

                                        this.dTCell = new HtmlTableCell();
                                        this.dTCell1 = new HtmlTableCell();
                                        this.dTCell2 = new HtmlTableCell();
                                        if (dt.Rows[tRows]["FieldName"].ToString() != "")
                                        {
                                            this.dTCell.InnerHtml = "<div class='blue_bold'>" + dt.Rows[tRows]["FieldName"].ToString() + "</div>";
                                            this.dTCell1.InnerText = ":";
                                        }
                                        dTCell.VAlign = "top";
                                        dTCell1.VAlign = "top";
                                        dTCell2.VAlign = "top";
                                        int FieldIdcatone = 0;
                                        if (dt.Rows[tRows]["FieldId"].ToString() != "")
                                        {
                                            // categoryfields.FieldId = Convert.ToInt32(dt.Rows[tRows]["FieldId"]);
                                            //***********imppppppppppppppppppppppp**************
                                            FieldIdcatone = Convert.ToInt32(dt.Rows[tRows]["FieldId"]);
                                            // FieldId = Convert.ToInt32(dt.Rows[tRows]["FieldId"]);
                                        }
                                        if (dt.Rows[tRows]["FieldType"].ToString() == "1")
                                        {
                                            TextBox txt = new TextBox();
                                            HiddenField hdnFieldId = new HiddenField();
                                            txt.CssClass = "textbox2";
                                            txt.ID = "txt" + FieldId;
                                            hdnFieldId.ID = "hdn" + FieldId;
                                            hdnFieldId.Value = dt.Rows[tRows]["FieldId"].ToString() + "_" + dt.Rows[tRows]["Default_Custom"].ToString();
                                            this.dTCell2.Controls.Add(txt);
                                            this.dTCell2.Controls.Add(hdnFieldId);
                                        }
                                        if (dt.Rows[tRows]["FieldType"].ToString() == "2")
                                        {
                                            CheckBoxList chk = new CheckBoxList();
                                            HiddenField hdnFieldId = new HiddenField();
                                            chk.ID = "chk" + FieldId;
                                            hdnFieldId.ID = "hdn" + FieldId;
                                            hdnFieldId.Value = dt.Rows[tRows]["FieldId"].ToString() + "_" + dt.Rows[tRows]["Default_Custom"].ToString();
                                            chk.RepeatDirection = RepeatDirection.Horizontal;
                                            if (dt.Rows[tRows]["Default_Custom"].ToString() == "C")
                                            {
                                                // categoryfields.populatedynamicrchk(ref chk);
                                                StuListCont.populatedynamicrchk(ref chk, FieldIdcatone);
                                            }
                                            this.dTCell2.Controls.Add(chk);
                                            this.dTCell2.Controls.Add(hdnFieldId);
                                        }
                                        if (dt.Rows[tRows]["FieldType"].ToString() == "3")
                                        {
                                            RadioButtonList rdb = new RadioButtonList();
                                            HiddenField hdnFieldId = new HiddenField();
                                            rdb.ID = "rdb" + FieldId;
                                            hdnFieldId.ID = "hdn" + FieldId;
                                            hdnFieldId.Value = dt.Rows[tRows]["FieldId"].ToString() + "_" + dt.Rows[tRows]["Default_Custom"].ToString();
                                            rdb.RepeatDirection = RepeatDirection.Horizontal;
                                            if (dt.Rows[tRows]["Default_Custom"].ToString() == "D")
                                            {
                                                if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 10)
                                                {
                                                    // categoryfields.PopulateGender(ref rdb);
                                                    StuListCont.PopulateGender(ref rdb);
                                                }
                                            }
                                            if (dt.Rows[tRows]["Default_Custom"].ToString() == "C")
                                            {
                                                // categoryfields.populatedynamicrbtn(ref rdb);
                                                //  StuListCont.populatedynamicrbtn(ref rdb, FieldId);
                                                StuListCont.populatedynamicrbtn(ref rdb, FieldIdcatone);
                                            }
                                            this.dTCell2.Controls.Add(rdb);
                                            this.dTCell2.Controls.Add(hdnFieldId);
                                        }
                                        if (dt.Rows[tRows]["FieldType"].ToString() == "4")
                                        {
                                            DropDownList ddl = new DropDownList();
                                            HiddenField hdnFieldId = new HiddenField();
                                            ddl.ID = "ddl" + FieldId;
                                            hdnFieldId.ID = "hdn" + FieldId;
                                            hdnFieldId.Value = dt.Rows[tRows]["FieldId"].ToString() + "_" + dt.Rows[tRows]["Default_Custom"].ToString();
                                            ddl.CssClass = "dropdown2";
                                            if (dt.Rows[tRows]["Default_Custom"].ToString() == "D")
                                            {
                                                if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 11)//ETHNICITY
                                                {
                                                    //categoryfields.populateEthnicity(ref ddl);
                                                    //**********18/05/2010*************
                                                    StuListCont.populateEthnicity(ref ddl, Convert.ToInt32(Session["SchoolID"]));
                                                }
                                                if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 15 || Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 16)//LANGUAGE
                                                {
                                                    // categoryfields.populateLanguage(ref ddl);
                                                    StuListCont.populateLanguage(ref ddl);
                                                }
                                                if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 18)//COUNTRY
                                                {
                                                    // categoryfields.populateCountry(ref ddl);
                                                    StuListCont.populateCountry(ref ddl);
                                                }
                                                if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 120)//START CONDITION
                                                {
                                                    // vmlBL.populateCountry(ref ddl);
                                                    // categoryfields.PopulateEnrollCdn(ref ddl);
                                                    StuListCont.PopulateEnrollCdn(ref ddl);
                                                }
                                                if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 110)//Calender
                                                {

                                                    // schoolcategory.populatecalender(ref ddl);
                                                    StuListCont.populatecalender(ref ddl, SchoolID);
                                                }

                                                //****************06/02/2010***********
                                                if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 210)//Religion
                                                {

                                                    StuListCont.populateReligion(ref ddl);
                                                }
                                            }
                                            if (dt.Rows[tRows]["Default_Custom"].ToString() == "C")
                                            {
                                                // categoryfields.populatedynamicddl(ref ddl);
                                                //StuListCont.populatedynamicddl(ref ddl, FieldId);
                                                StuListCont.populatedynamicddl(ref ddl, FieldIdcatone);
                                            }
                                            this.dTCell2.Controls.Add(ddl);
                                            this.dTCell2.Controls.Add(hdnFieldId);
                                        }
                                        if (dt.Rows[tRows]["FieldType"].ToString() == "5")
                                        {
                                            Label lbl = new Label();
                                            HiddenField hdnFieldId = new HiddenField();
                                            lbl.ID = "lbl" + FieldId;
                                            hdnFieldId.ID = "hdn" + FieldId;
                                            hdnFieldId.Value = dt.Rows[tRows]["FieldId"].ToString() + "_" + dt.Rows[tRows]["Default_Custom"].ToString();
                                            this.dTCell2.Controls.Add(lbl);
                                            this.dTCell2.Controls.Add(hdnFieldId);
                                        }

                                        //*******************28/04/2010*******************
                                        if (dt.Rows[tRows]["FieldType"].ToString() == "6")
                                        {
                                            Control control = new Control();
                                            control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                                            HiddenField hdnFieldId = new HiddenField();



                                            control.ID = "uc" + FieldId;
                                            hdnFieldId.ID = "hdn" + FieldId;
                                            hdnFieldId.Value = dt.Rows[tRows]["FieldId"].ToString() + "_" + dt.Rows[tRows]["Default_Custom"].ToString();
                                            //****Problem on this line**************
                                            Session["control"] = control;
                                            this.dTCell2.Controls.Add((Control)Session["control"]);
                                            this.dTCell2.Controls.Add(hdnFieldId);


                                        }
                                        //************************************************

                                        FieldId++;

                                        this.dTRow.Controls.Add(this.dTCell);
                                        this.dTRow.Controls.Add(this.dTCell1);
                                        this.dTRow.Controls.Add(this.dTCell2);
                                        dt.Rows.RemoveAt(0);
                                        tRows = 0;
                                    }

                                    this.dTable.Controls.Add(dTRow);

                                }
                                else
                                {
                                    break;
                                }
                            }


                            this.dTRow = new HtmlTableRow();
                            this.dTCell = new HtmlTableCell();
                            this.dTCell.InnerHtml = "<div class='clear_small'></div>";
                            this.dTCell.ColSpan = 6;
                            this.dTRow.Cells.Add(dTCell);
                            this.dTable.Rows.Insert(tCellsquotient + 1, dTRow);



                            phAllFieldHolder.Controls.Add(dTable);

                            //*******************************************

                            //IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
                            //hdnCatId.Value = dt.Rows[0][0].ToString();
                            //hdnInitialCatId.Value = hdnCatId.Value;
                            //CatId = Convert.ToInt32(hdnCatId.Value);
                            ////ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                            //SchoolID = Convert.ToInt32(Session["SchoolID"]);
                            //// TreeView1.Nodes[Convert.ToInt32(hdnCatId.Value)].Selected = true;
                            //string CatNameq = TreeView1.SelectedNode.Text.ToString();
                            //DataTable dtFields = schoolcategory.GetFieldsByCategory();
                            ////*******************
                            //DataTable dtFields = schoolcategory.GetFieldsByCategoryStudentBusiness(SchoolID, CatId, Session["MLUICulture"].ToString());
                            //ibtnAdd.Visible = false;

                            //this.dTable.CellPadding = 2;
                            //this.dTable.CellSpacing = 0;
                            //this.dTable.Border = 0;
                            //this.dTable.Width = "100%";
                            ////this.dTable.Attributes.Add("class", "darkblue_content");

                            //int tRows;
                            //int tCells = 2;
                            //int tCellsmod = Convert.ToInt32(dtFields.Rows.Count % tCells);

                            //int tCellsquotient = Convert.ToInt32(dtFields.Rows.Count / tCells);
                            //if (tCellsmod != 0)
                            //{
                            //    tCellsquotient = tCellsquotient + 1;
                            //    int j = dtFields.Rows.Count;

                            //    DataRow dr = dtFields.NewRow();
                            //    dtFields.Rows.Add(dr);

                            //}

                            //this.dTRow = new HtmlTableRow();
                            //this.dTCell = new HtmlTableCell();
                            //this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + CatName.ToString() + "</div>";
                            //this.dTCell.ColSpan = 6;
                            //this.dTRow.Cells.Add(dTCell);
                            //this.dTable.Rows.Insert(0, dTRow);

                            //for (tRows = 0; tRows < tCellsquotient; tRows++)
                            //{
                            //    tRows = 0;
                            //    if (dtFields.Rows.Count > 0 || dtFields.Rows.Count != 0)
                            //    {

                            //        this.dTRow = new HtmlTableRow();
                            //        for (tCells = 0; tCells < 2; tCells++)
                            //        {

                            //            this.dTCell = new HtmlTableCell();
                            //            this.dTCell1 = new HtmlTableCell();
                            //            this.dTCell2 = new HtmlTableCell();
                            //            dTCell.Attributes.Add("class", "student_grid");
                            //            if (dtFields.Rows[tRows]["FieldName"].ToString() != "")
                            //            {
                            //                this.dTCell.InnerHtml = "<div class='blue_bold'>" + dtFields.Rows[tRows]["FieldName"].ToString() + "</div>";
                            //                this.dTCell1.InnerText = ":";
                            //            }
                            //            dTCell.Align = "left";
                            //            dTCell2.Align = "left";
                            //            int FieldIdcatone = 0;
                            //            if (dtFields.Rows[tRows]["FieldId"].ToString() != "")
                            //            {
                            //                // categoryfields.FieldId = Convert.ToInt32(dtFields.Rows[tRows]["FieldId"]);
                            //                FieldIdcatone = Convert.ToInt32(dtFields.Rows[tRows]["FieldId"]);
                            //            }
                            //            if (dtFields.Rows[tRows]["FieldType"].ToString() == "1")
                            //            {
                            //                TextBox txt = new TextBox();
                            //                HiddenField hdnFieldId = new HiddenField();
                            //                txt.CssClass = "textbox2";
                            //                txt.ID = "txt" + FieldId;
                            //                hdnFieldId.ID = "hdn" + FieldId;
                            //                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                            //                this.dTCell2.Controls.Add(txt);
                            //                this.dTCell2.Controls.Add(hdnFieldId);
                            //            }
                            //            if (dtFields.Rows[tRows]["FieldType"].ToString() == "2")
                            //            {
                            //                CheckBoxList chk = new CheckBoxList();
                            //                HiddenField hdnFieldId = new HiddenField();
                            //                chk.ID = "chk" + FieldId;
                            //                hdnFieldId.ID = "hdn" + FieldId;
                            //                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                            //                chk.RepeatDirection = RepeatDirection.Horizontal;
                            //                if (dtFields.Rows[tRows]["Default_Custom"].ToString() == "C")
                            //                {
                            //                    //  categoryfields.populatedynamicrchk(ref chk);
                            //                    StuListCont.populatedynamicrchk(ref chk, FieldIdcatone);
                            //                }
                            //                this.dTCell2.Controls.Add(chk);
                            //                this.dTCell2.Controls.Add(hdnFieldId);
                            //            }
                            //            if (dtFields.Rows[tRows]["FieldType"].ToString() == "3")
                            //            {
                            //                RadioButtonList rdb = new RadioButtonList();
                            //                HiddenField hdnFieldId = new HiddenField();
                            //                rdb.ID = "rdb" + FieldId;
                            //                hdnFieldId.ID = "hdn" + FieldId;
                            //                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                            //                rdb.RepeatDirection = RepeatDirection.Horizontal;
                            //                if (dtFields.Rows[tRows]["Default_Custom"].ToString() == "D")
                            //                {
                            //                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 10)
                            //                    {
                            //                        // categoryfields.PopulateGender(ref rdb);
                            //                        StuListCont.PopulateGender(ref rdb);
                            //                    }
                            //                }
                            //                if (dtFields.Rows[tRows]["Default_Custom"].ToString() == "C")
                            //                {
                            //                    // categoryfields.populatedynamicrbtn(ref rdb);
                            //                    StuListCont.populatedynamicrbtn(ref rdb, FieldIdcatone);
                            //                }
                            //                this.dTCell2.Controls.Add(rdb);
                            //                this.dTCell2.Controls.Add(hdnFieldId);
                            //            }
                            //            if (dtFields.Rows[tRows]["FieldType"].ToString() == "4")
                            //            {
                            //                DropDownList ddl = new DropDownList();
                            //                HiddenField hdnFieldId = new HiddenField();
                            //                ddl.ID = "ddl" + FieldId;
                            //                hdnFieldId.ID = "hdn" + FieldId;
                            //                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                            //                ddl.CssClass = "dropdown2";
                            //                if (dtFields.Rows[tRows]["Default_Custom"].ToString() == "D")
                            //                {
                            //                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 11)//ETHNICITY
                            //                    {
                            //                        //categoryfields.populateEthnicity(ref ddl);
                            //                        StuListCont.populateEthnicity(ref ddl);
                            //                    }
                            //                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 15 || Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 16)//LANGUAGE
                            //                    {
                            //                        // categoryfields.populateLanguage(ref ddl);
                            //                        StuListCont.populateLanguage(ref ddl);
                            //                    }
                            //                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 18)//COUNTRY
                            //                    {
                            //                        // categoryfields.populateCountry(ref ddl);
                            //                        StuListCont.populateCountry(ref ddl);
                            //                    }
                            //                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 120)//START CONDITION
                            //                    {
                            //                        // vmlBL.populateCountry(ref ddl);
                            //                        // categoryfields.PopulateEnrollCdn(ref ddl);
                            //                        StuListCont.PopulateEnrollCdn(ref ddl);
                            //                    }
                            //                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 110)//Calender
                            //                    {

                            //                        //STBL.populatecalender(ref ddl);
                            //                        StuListCont.populatecalender(ref ddl, SchoolID);
                            //                    }
                            //                }
                            //                if (dtFields.Rows[tRows]["Default_Custom"].ToString() == "C")
                            //                {
                            //                    // categoryfields.populatedynamicddl(ref ddl);
                            //                    StuListCont.populatedynamicddl(ref ddl, FieldIdcatone);
                            //                }
                            //                this.dTCell2.Controls.Add(ddl);
                            //                this.dTCell2.Controls.Add(hdnFieldId);
                            //            }
                            //            if (dtFields.Rows[tRows]["FieldType"].ToString() == "5")
                            //            {
                            //                Label lbl = new Label();
                            //                HiddenField hdnFieldId = new HiddenField();
                            //                lbl.ID = "lbl" + FieldId;
                            //                hdnFieldId.ID = "hdn" + FieldId;
                            //                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                            //                //StudentBL stbl2 = new StudentBL();
                            //                this.dTCell2.Controls.Add(lbl);
                            //                this.dTCell2.Controls.Add(hdnFieldId);
                            //            }


                            //            //*******************28/04/2010*******************
                            //            if (dtFields.Rows[tRows]["FieldType"].ToString() == "6")
                            //            {

                            //                HiddenField hdnFieldId = new HiddenField();
                            //                hdnFieldId.ID = "hdn" + FieldId;
                            //                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                            //                Control control = new Control();
                            //                control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                            //                control.ID = "uc" + FieldId;
                            //                this.dTCell2.Controls.Add(control);
                            //                this.dTCell2.Controls.Add(hdnFieldId);



                            //            }
                            //            //************************************************
                            //            this.dTRow.Controls.Add(dTCell);
                            //            this.dTRow.Controls.Add(dTCell1);
                            //            this.dTRow.Controls.Add(dTCell2);
                            //            dtFields.Rows.RemoveAt(0);
                            //            tRows = 0;
                            //            FieldId++;
                            //        }
                            //        this.dTable.Controls.Add(dTRow);

                            //    }
                            //    else
                            //    {
                            //        break;
                            //    }
                            //    // FieldId++;
                            //}

                            //this.dTRow = new HtmlTableRow();
                            //this.dTCell = new HtmlTableCell();
                            //this.dTCell.InnerHtml = "<div class='clear_small'></div>";
                            //this.dTCell.ColSpan = 6;
                            //this.dTRow.Cells.Add(dTCell);
                            //this.dTable.Rows.Insert(tCellsquotient + 1, dTRow);

                            //phAllFieldHolder.Controls.Add(dTable);



                        }
                        else
                        {
                            //Special and gifted in selcted node change
                            tblSchEnrInfo.Visible = false;
                            TMInfo.Visible = false;
                            tblProgram.Visible = true;
                            ibtnAdd.Visible = false;



                        }
                    }
                    else
                    {
                        //School Enrollment for treeview node change starts here
                        DropDownList ddl = new DropDownList();
                        tblProgram.Visible = false;
                        ibtnAdd.Visible = false;
                        ibtnEnrInfo.Visible = true;
                        CatId = Convert.ToInt32(hdnCatId.Value);
                        hdnInitialCatId.Value = hdnCatId.Value;
                        ibtnEnrInfo.Visible = true;
                        gvEnrInfo.Visible = true;
                        rptrSchlInfo.Visible = true;

                        // DataTable dtschlinfo = schoolcategory.GetFieldsByCategory();
                        DataTable dtschlinfo = schoolcategory.GetFieldsByCategoryStudentBusiness(SchoolID, CatId, Session["MLUICulture"].ToString());



                        tblSchEnrInfo.Visible = true;

                        //for (int i = 0; i < dtschlinfo.Rows.Count; i++)
                        //{
                        //    if (Convert.ToInt32(dtschlinfo.Rows[i]["FieldId"].ToString()) == 110)//Calender
                        //    {

                        //        schoolcategory.populatecalender(ref ddl);
                        //    }
                        //}
                        rptrSchlInfo.DataSource = dtschlinfo;
                        rptrSchlInfo.DataBind();

                        DataTable SessiondtEnrol = (DataTable)Session["Enroltable"];
                        if (SessiondtEnrol != null)
                        {
                            gvEnrInfo.DataSource = SessiondtEnrol;
                            gvEnrInfo.DataBind();
                        }
                        else
                        {
                            DataTable dtEnrol = new DataTable();
                            dtEnrol.Columns.Add("AttStrtDate");
                            dtEnrol.Columns.Add("ExitDate");
                            dtEnrol.Columns.Add("ExitCode");
                            dtEnrol.Columns.Add("Exitreason");
                            dtEnrol.Columns.Add("StartCondition");
                            //added
                            dtEnrol.Columns.Add("ExitCodeValue");
                            DataRow dr = dtEnrol.NewRow();
                            dtEnrol.Rows.Add(dr);
                            gvEnrInfo.DataSource = dtEnrol;
                            gvEnrInfo.DataBind();
                        }








                    }
                }
                else
                {

                    //StudentBL schoolcategory = new StudentBL();
                    // hdnCatId.Value = dt.Rows[0][0].ToString();
                    ibtnAdd.Visible = false;
                    CatId = Convert.ToInt32(hdnCatId.Value);
                    hdnInitialCatId.Value = hdnCatId.Value;
                    btnImmuAdd.Visible = true;
                    ibtnAlertAdd.Visible = true;
                    ibtnNursevisitAdd.Visible = true;
                    GVImmunization.Visible = true;
                    GVMedicalAlert.Visible = true;
                    GVNurseVisitRec.Visible = true;
                    ibtnVace.Visible = true;
                    rptrVaceField.Visible = true;
                    rptMedicalInfo.Visible = true;
                    TMInfo.Visible = true;

                    DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
                    if (SessiondtImmu != null)
                    {
                        GVImmunization.DataSource = SessiondtImmu;
                        GVImmunization.DataBind();
                    }
                    else
                    {
                        DataTable dtImmu = new DataTable();
                        dtImmu.Columns.Add("Type");
                        dtImmu.Columns.Add("Date");
                        dtImmu.Columns.Add("Comment");
                        dtImmu.Columns.Add("Typevalue");
                        DataRow dr = dtImmu.NewRow();
                        dtImmu.Rows.Add(dr);
                        GVImmunization.DataSource = dtImmu;
                        GVImmunization.DataBind();
                    }
                    DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
                    if (SessiondtAlert != null)
                    {
                        GVMedicalAlert.DataSource = SessiondtAlert;
                        GVMedicalAlert.DataBind();
                    }
                    else
                    {
                        DataTable dtAlert = new DataTable();
                        dtAlert.Columns.Add("Alert");
                        DataRow dr = dtAlert.NewRow();
                        dtAlert.Rows.Add(dr);
                        GVMedicalAlert.DataSource = dtAlert;
                        GVMedicalAlert.DataBind();
                    }

                    DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
                    if (SessiondtNurseVisit != null)
                    {
                        GVNurseVisitRec.DataSource = SessiondtNurseVisit;
                        GVNurseVisitRec.DataBind();
                    }
                    else
                    {
                        DataTable dtNurseVisit = new DataTable();
                        dtNurseVisit.Columns.Add("Date");
                        dtNurseVisit.Columns.Add("TimeIn");
                        dtNurseVisit.Columns.Add("TimeOut");
                        dtNurseVisit.Columns.Add("Reason");
                        dtNurseVisit.Columns.Add("Result");
                        dtNurseVisit.Columns.Add("Comments");
                        DataRow dr = dtNurseVisit.NewRow();
                        dtNurseVisit.Rows.Add(dr);
                        GVNurseVisitRec.DataSource = dtNurseVisit;
                        GVNurseVisitRec.DataBind();
                    }

                    //DataTable dtVaccinationDetails = new DataTable();
                    //dtVaccinationDetails.Columns.Add("Vaccination_Code");
                    //dtVaccinationDetails.Columns.Add("Vaccination_Name");
                    //dtVaccinationDetails.Columns.Add("Vaccination_Date");
                    //dtVaccinationDetails.Columns.Add("Vaccination_Expiry_Date");
                    //dtVaccinationDetails.Columns.Add("Waiver");

                    //DataRow drvacc = dtVaccinationDetails.NewRow();
                    //dtVaccinationDetails.Rows.Add(drvacc);
                    //GVVccination.DataSource = dtVaccinationDetails;
                    //GVVccination.DataBind();

                    //PopulateVccinationGridview();

                    DataTable dtMedicalInfo = new DataTable();
                    dtMedicalInfo = schoolcategory.GetMedicalInfoFieldsStudentBusiness(SchoolID, CatId);
                    //dtMedicalInfo = schoolcategory.GetMedicalInfoFields();
                    rptMedicalInfo.DataSource = dtMedicalInfo;
                    rptMedicalInfo.DataBind();

                    //DataTable dtVcea = new DataTable();
                    //dtVcea = schoolcategory.GetVaccinationFields();
                    //rptrVaceField.DataSource = dtVcea;
                    //rptrVaceField.DataBind();

                }
            }

            if (Treepos == 0)
            {
                btnSave.Visible = false;
                btnPrev.Visible = false;
                btnNext.Visible = true;

            }
            else if ((Treepos + 1) == Convert.ToInt32(TreeView1.Nodes.Count))
            {
                btnSave.Visible = true;
                btnPrev.Visible = true;
                btnNext.Visible = false;
            }
            else
            {
                btnSave.Visible = false;
                btnPrev.Visible = true;
                btnNext.Visible = true;
            }

        }
        catch
        {

        }
    }


    protected void btnNext_Click(object sender, ImageClickEventArgs e)
    {
        try
        {

            divPhotoUpload.Style.Add("Display", "none");
            divOuter.Style.Add("Display", "none");
            StoreFieldDataIntoDatatable();


            int Count = dTable.Rows.Count;

            for (int k = Count - 1; k >= 0; k--)
            {
                this.dTable.Rows.RemoveAt(k);
            }


            if (hdnCatId.Value.ToString() == "5")
            {

                StoreMedicalInfoFieldDataIntoDatatable();
                //StoreVaccinationFieldDataIntoDatatable();
                DataStoreProgramForVaccination();

            }

            //storing enrollment info

            if (hdnCatId.Value.ToString() == "4")
            {

                StoreSchoolInfoFieldDataIntoDatatable();


            }



            PopulateNextFields();
            if (hdnCatId.Value.ToString() == "5")
            {

                PopulateMedicalInfoFieldData();
                //PopulateVaccinationFieldData();
                PopulateVccinationValue();

            }
            if (hdnCatId.Value.ToString() == "4")
            {

                PopulateSchoolInfoFieldData();


            }
            if (hdnCatId.Value.ToString() == "8")
            {

                PopulateGiftValue();
                PopulateSpecialValue();


            }

            PopulateFieldData();

        }
        catch (Exception ex)
        {
            string error = ex.ToString();
        }

    }


    protected void PopulateNextFields()
    {
        //EntryFormLayoutBL categoryfields = new EntryFormLayoutBL();
        OpenSISWCFServiceStudentFormLayoutClient categoryfields = new OpenSISWCFServiceStudentFormLayoutClient();
        try
        {
            //StudentSetupBL StSuBL = new StudentSetupBL();
            //StudentBL STBL = new StudentBL();
            OpenSISWCFServiceStudentSetupClient StSuBL = new OpenSISWCFServiceStudentSetupClient();
            IopenSISServiceStudentClient STBL = new IopenSISServiceStudentClient();
            int CatId = Convert.ToInt32(hdnCatId.Value);
            //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);

            //TreeView1.Nodes[Convert.ToInt32(hdnCatId.Value)].Selected =true;


            //DataTable dt = STBL.GetNextCategory();
            DataTable dt = STBL.GetNextCategoryStudentBusiness(SchoolID, CatId);
            foreach (TreeNode tn in TreeView1.Nodes)
            {
                string t = tn.Value.Split(",".ToCharArray())[0];
                if (t == dt.Rows[0][0].ToString())
                {

                    tn.Selected = true;

                }

            }
            string CatName = TreeView1.SelectedNode.Text.ToString();
            int FieldId = 0;
            if (dt.Rows.Count > 0)
            {

                if (dt.Rows[0][0].ToString() != "3")
                {
                    btnImmuAdd.Visible = false;
                    ibtnAlertAdd.Visible = false;
                    ibtnNursevisitAdd.Visible = false;
                    GVImmunization.Visible = false;
                    GVMedicalAlert.Visible = false;
                    GVNurseVisitRec.Visible = false;
                    ibtnVace.Visible = false;
                    rptrVaceField.Visible = false;
                    rptMedicalInfo.Visible = false;
                    TMInfo.Visible = false;
                    tblSchEnrInfo.Visible = false;
                    rptrSchlInfo.Visible = false;
                    gvEnrInfo.Visible = false;

                    tblSchEnrInfo.Visible = false;
                    rptrSchlInfo.Visible = false;
                    gvEnrInfo.Visible = false;
                    tblProgram.Visible = false;

                    if (dt.Rows[0][0].ToString() != "5")
                    {
                        if (dt.Rows[0][0].ToString() != "4")
                        {
                            if (dt.Rows[0][0].ToString() != "8")
                            {

                                //StudentBL schoolcategory = new StudentBL();
                                IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
                                hdnCatId.Value = dt.Rows[0][0].ToString();
                                CatId = Convert.ToInt32(hdnCatId.Value);
                                hdnInitialCatId.Value = hdnCatId.Value;
                                //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                                //schoolcategory.SchoolID = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
                                SchoolID = Convert.ToInt32(Session["SchoolID"]);
                                //DataTable dtFields = schoolcategory.GetFieldsByCategory();
                                DataTable dtFields = schoolcategory.GetFieldsByCategoryStudentBusiness(SchoolID, CatId, Session["MLUICulture"].ToString());
                                ibtnAdd.Visible = false;

                                this.dTable.CellPadding = 2;
                                this.dTable.CellSpacing = 0;
                                this.dTable.Border = 0;
                                this.dTable.Width = "100%";
                                //this.dTable.Attributes.Add("class", "darkblue_content");
                                int tRows;
                                int tCells = 2;
                                int tCellsmod = Convert.ToInt32(dtFields.Rows.Count % tCells);

                                int tCellsquotient = Convert.ToInt32(dtFields.Rows.Count / tCells);
                                if (tCellsmod != 0)
                                {
                                    tCellsquotient = tCellsquotient + 1;
                                    DataRow dr = dtFields.NewRow();
                                    dtFields.Rows.Add(dr);

                                }

                                this.dTRow = new HtmlTableRow();
                                this.dTCell = new HtmlTableCell();
                                this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + CatName.ToString() + "</div>";
                                this.dTCell.ColSpan = 6;
                                this.dTRow.Cells.Add(dTCell);
                                this.dTable.Rows.Insert(0, dTRow);

                                for (tRows = 0; tRows < tCellsquotient; tRows++)
                                {
                                    tRows = 0;
                                    if (dtFields.Rows.Count > 0 || dtFields.Rows.Count != 0)
                                    {

                                        this.dTRow = new HtmlTableRow();
                                        for (tCells = 0; tCells < 2; tCells++)
                                        {

                                            this.dTCell = new HtmlTableCell();
                                            this.dTCell1 = new HtmlTableCell();
                                            this.dTCell2 = new HtmlTableCell();
                                            dTCell.Attributes.Add("class", "student_grid");


                                            if (dtFields.Rows[tRows]["FieldName"].ToString() != "")
                                            {
                                                this.dTCell.InnerHtml = "<div class='blue_bold'>" + dtFields.Rows[tRows]["FieldName"].ToString() + "</div>";
                                                this.dTCell1.InnerText = ":";
                                            }
                                            dTCell.Align = "left";
                                            dTCell2.Align = "left";
                                            //*************imp_fieldID**********
                                            int FieldIdChk = 0;
                                            if (dtFields.Rows[tRows]["FieldId"].ToString() != "")
                                            {
                                                FieldIdChk = Convert.ToInt32(dtFields.Rows[tRows]["FieldId"]);
                                            }
                                            if (dtFields.Rows[tRows]["FieldType"].ToString() == "1")
                                            {
                                                TextBox txt = new TextBox();
                                                HiddenField hdnFieldId = new HiddenField();
                                                txt.CssClass = "textbox2";
                                                txt.ID = "txt" + FieldId;
                                                hdnFieldId.ID = "hdn" + FieldId;
                                                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                                                this.dTCell2.Controls.Add(txt);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            if (dtFields.Rows[tRows]["FieldType"].ToString() == "2")
                                            {
                                                CheckBoxList chk = new CheckBoxList();
                                                HiddenField hdnFieldId = new HiddenField();
                                                chk.ID = "chk" + FieldId;
                                                hdnFieldId.ID = "hdn" + FieldId;
                                                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                                                chk.RepeatDirection = RepeatDirection.Horizontal;
                                                if (dtFields.Rows[tRows]["Default_Custom"].ToString() == "C")
                                                {
                                                    // categoryfields.populatedynamicrchk(ref chk);
                                                    StuListCont.populatedynamicrchk(ref chk, FieldIdChk);
                                                }
                                                this.dTCell2.Controls.Add(chk);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            if (dtFields.Rows[tRows]["FieldType"].ToString() == "3")
                                            {
                                                RadioButtonList rdb = new RadioButtonList();
                                                HiddenField hdnFieldId = new HiddenField();
                                                rdb.ID = "rdb" + FieldId;
                                                hdnFieldId.ID = "hdn" + FieldId;
                                                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                                                rdb.RepeatDirection = RepeatDirection.Horizontal;
                                                if (dtFields.Rows[tRows]["Default_Custom"].ToString() == "D")
                                                {
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 10)
                                                    {
                                                        // categoryfields.PopulateGender(ref rdb);
                                                        StuListCont.PopulateGender(ref rdb);
                                                    }
                                                }
                                                if (dtFields.Rows[tRows]["Default_Custom"].ToString() == "C")
                                                {
                                                    //categoryfields.populatedynamicrbtn(ref rdb);
                                                    StuListCont.populatedynamicrbtn(ref rdb, FieldIdChk);
                                                }
                                                this.dTCell2.Controls.Add(rdb);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            if (dtFields.Rows[tRows]["FieldType"].ToString() == "4")
                                            {
                                                DropDownList ddl = new DropDownList();
                                                HiddenField hdnFieldId = new HiddenField();
                                                ddl.ID = "ddl" + FieldId;
                                                hdnFieldId.ID = "hdn" + FieldId;
                                                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                                                ddl.CssClass = "dropdown2";
                                                if (dtFields.Rows[tRows]["Default_Custom"].ToString() == "D")
                                                {
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 11)//ETHNICITY
                                                    {
                                                        // categoryfields.populateEthnicity(ref ddl);
                                                        //*********1805/2010**********
                                                        StuListCont.populateEthnicity(ref ddl, Convert.ToInt32(Session["SchoolID"]));
                                                    }
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 15 || Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 16)//LANGUAGE
                                                    {
                                                        //categoryfields.populateLanguage(ref ddl);
                                                        StuListCont.populateLanguage(ref ddl);
                                                    }
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 18)//COUNTRY
                                                    {
                                                        // categoryfields.populateCountry(ref ddl);
                                                        StuListCont.populateCountry(ref ddl);
                                                    }
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 120)//START CONDITION
                                                    {
                                                        // vmlBL.populateCountry(ref ddl);
                                                        // categoryfields.PopulateEnrollCdn(ref ddl);
                                                        StuListCont.PopulateEnrollCdn(ref ddl);
                                                    }
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 110)//Calender
                                                    {

                                                        // STBL.populatecalender(ref ddl);
                                                        StuListCont.populatecalender(ref ddl, SchoolID);
                                                    }
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 210)//Religion
                                                    {


                                                        StuListCont.populateReligion(ref ddl);
                                                    }
                                                }
                                                if (dtFields.Rows[tRows]["Default_Custom"].ToString() == "C")
                                                {
                                                    // categoryfields.populatedynamicddl(ref ddl);
                                                    StuListCont.populatedynamicddl(ref ddl, FieldIdChk);
                                                }
                                                this.dTCell2.Controls.Add(ddl);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            if (dtFields.Rows[tRows]["FieldType"].ToString() == "5")
                                            {
                                                Label lbl = new Label();
                                                HiddenField hdnFieldId = new HiddenField();
                                                lbl.ID = "lbl" + FieldId;
                                                hdnFieldId.ID = "hdn" + FieldId;
                                                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                                                this.dTCell2.Controls.Add(lbl);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }

                                            //*******************28/04/2010*******************
                                            if (dtFields.Rows[tRows]["FieldType"].ToString() == "6")
                                            {
                                                HiddenField hdnFieldId = new HiddenField();
                                                hdnFieldId.ID = "hdn" + FieldId;
                                                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();

                                                var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                                                control.ID = "uc" + FieldId;
                                                this.dTCell2.Controls.Add(control);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            //************************************************

                                            this.dTRow.Controls.Add(dTCell);
                                            this.dTRow.Controls.Add(dTCell1);
                                            this.dTRow.Controls.Add(dTCell2);
                                            dtFields.Rows.RemoveAt(0);
                                            tRows = 0;
                                            FieldId++;
                                        }
                                        this.dTable.Controls.Add(dTRow);
                                        // FieldId++;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }

                                this.dTRow = new HtmlTableRow();
                                this.dTCell = new HtmlTableCell();
                                this.dTCell.InnerHtml = "<div class='clear_small'></div>";
                                this.dTCell.ColSpan = 6;
                                this.dTRow.Cells.Add(dTCell);
                                this.dTable.Rows.Insert(tCellsquotient + 1, dTRow);

                                phAllFieldHolder.Controls.Add(dTable);
                            }
                            else
                            {
                                //Special and gifted in next
                                //StudentBL schoolcategory = new StudentBL();
                                IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
                                tblSchEnrInfo.Visible = false;
                                TMInfo.Visible = false;
                                tblProgram.Visible = true;
                                ibtnAdd.Visible = false;
                                hdnCatId.Value = dt.Rows[0][0].ToString();
                                CatId = Convert.ToInt32(hdnCatId.Value);
                                hdnInitialCatId.Value = hdnCatId.Value;


                            }
                        }
                        else
                        {
                            //enrollment populatenext
                            DropDownList ddl = new DropDownList();
                            ibtnEnrInfo.Visible = true;
                            tblSchEnrInfo.Visible = true;
                            gvEnrInfo.Visible = true;
                            rptrSchlInfo.Visible = true;
                            //StudentBL schoolcategory = new StudentBL();
                            IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
                            //schoolcategory.SchoolID = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
                            SchoolID = Convert.ToInt32(Session["SchoolID"]);
                            hdnCatId.Value = dt.Rows[0][0].ToString();
                            CatId = Convert.ToInt32(dt.Rows[0][0].ToString());
                            hdnInitialCatId.Value = hdnCatId.Value;

                            // DataTable dtschlinfo = schoolcategory.GetFieldsByCategory();
                            DataTable dtschlinfo = schoolcategory.GetFieldsByCategoryStudentBusiness(SchoolID, CatId, Session["MLUICulture"].ToString());
                            rptrSchlInfo.DataSource = dtschlinfo;
                            rptrSchlInfo.DataBind();

                            //for (int i = 0; i < dtschlinfo.Rows.Count; i++)
                            //{
                            //    if (Convert.ToInt32(dtschlinfo.Rows[i]["FieldId"].ToString()) == 110)//Calender
                            //    {

                            //        schoolcategory.populatecalender(ref ddl);
                            //    }
                            //}
                            DataTable SessiondtEnrol = (DataTable)Session["Enroltable"];
                            if (SessiondtEnrol != null)
                            {
                                gvEnrInfo.DataSource = SessiondtEnrol;
                                gvEnrInfo.DataBind();
                            }
                            else
                            {
                                DataTable dtEnrol = new DataTable();
                                dtEnrol.Columns.Add("AttStrtDate");
                                dtEnrol.Columns.Add("ExitDate");
                                dtEnrol.Columns.Add("ExitCode");
                                dtEnrol.Columns.Add("Exitreason");
                                dtEnrol.Columns.Add("StartCondition");
                                //added
                                dtEnrol.Columns.Add("ExitCodeValue");
                                DataRow dr = dtEnrol.NewRow();
                                dtEnrol.Rows.Add(dr);
                                gvEnrInfo.DataSource = dtEnrol;
                                gvEnrInfo.DataBind();
                            }



                        }
                    }
                    else
                    {
                        //StudentBL schoolcategory = new StudentBL();
                        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
                        hdnCatId.Value = dt.Rows[0][0].ToString();
                        CatId = Convert.ToInt32(hdnCatId.Value);
                        hdnInitialCatId.Value = hdnCatId.Value;
                        btnImmuAdd.Visible = true;
                        ibtnAlertAdd.Visible = true;
                        ibtnNursevisitAdd.Visible = true;
                        GVImmunization.Visible = true;
                        GVMedicalAlert.Visible = true;
                        GVNurseVisitRec.Visible = true;
                        ibtnVace.Visible = true;
                        rptrVaceField.Visible = true;
                        rptMedicalInfo.Visible = true;
                        TMInfo.Visible = true;

                        DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
                        if (SessiondtImmu != null)
                        {
                            GVImmunization.DataSource = SessiondtImmu;
                            GVImmunization.DataBind();
                        }
                        else
                        {
                            DataTable dtImmu = new DataTable();
                            dtImmu.Columns.Add("Type");
                            dtImmu.Columns.Add("Date");
                            dtImmu.Columns.Add("Comment");
                            dtImmu.Columns.Add("Typevalue");
                            DataRow dr = dtImmu.NewRow();
                            dtImmu.Rows.Add(dr);
                            GVImmunization.DataSource = dtImmu;
                            GVImmunization.DataBind();
                        }
                        DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
                        if (SessiondtAlert != null)
                        {
                            GVMedicalAlert.DataSource = SessiondtAlert;
                            GVMedicalAlert.DataBind();
                        }
                        else
                        {
                            DataTable dtAlert = new DataTable();
                            dtAlert.Columns.Add("Alert");
                            DataRow dr = dtAlert.NewRow();
                            dtAlert.Rows.Add(dr);
                            GVMedicalAlert.DataSource = dtAlert;
                            GVMedicalAlert.DataBind();
                        }

                        DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
                        if (SessiondtNurseVisit != null)
                        {
                            GVNurseVisitRec.DataSource = SessiondtNurseVisit;
                            GVNurseVisitRec.DataBind();
                        }
                        else
                        {
                            DataTable dtNurseVisit = new DataTable();
                            dtNurseVisit.Columns.Add("Date");
                            dtNurseVisit.Columns.Add("TimeIn");
                            dtNurseVisit.Columns.Add("TimeOut");
                            dtNurseVisit.Columns.Add("Reason");
                            dtNurseVisit.Columns.Add("Result");
                            dtNurseVisit.Columns.Add("Comments");
                            DataRow dr = dtNurseVisit.NewRow();
                            dtNurseVisit.Rows.Add(dr);
                            GVNurseVisitRec.DataSource = dtNurseVisit;
                            GVNurseVisitRec.DataBind();
                        }


                        //DataTable dtVaccinationDetails = new DataTable();
                        //dtVaccinationDetails.Columns.Add("Vaccination_Code");
                        //dtVaccinationDetails.Columns.Add("Vaccination_Name");
                        //dtVaccinationDetails.Columns.Add("Vaccination_Date");
                        //dtVaccinationDetails.Columns.Add("Vaccination_Expiry_Date");
                        //dtVaccinationDetails.Columns.Add("Waiver");

                        //DataRow drvacc = dtVaccinationDetails.NewRow();
                        //dtVaccinationDetails.Rows.Add(drvacc);
                        //GVVccination.DataSource = dtVaccinationDetails;
                        //GVVccination.DataBind();
                        //PopulateVccinationGridview();

                        DataTable dtMedicalInfo = new DataTable();
                        //dtMedicalInfo = schoolcategory.GetMedicalInfoFields();
                        dtMedicalInfo = schoolcategory.GetMedicalInfoFieldsStudentBusiness(SchoolID, CatId);
                        rptMedicalInfo.DataSource = dtMedicalInfo;
                        rptMedicalInfo.DataBind();

                        //DataTable dtVcea = new DataTable();
                        //dtVcea = schoolcategory.GetVaccinationFields();
                        //rptrVaceField.DataSource = dtVcea;
                        //rptrVaceField.DataBind();

                    }
                }

                else
                {

                    tblProgram.Visible = false;
                    // StudentBL schoolcategory = new StudentBL();
                    IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
                    hdnCatId.Value = dt.Rows[0][0].ToString();
                    hdnInitialCatId.Value = hdnCatId.Value;
                    CatId = Convert.ToInt32(hdnCatId.Value);
                    //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                    //schoolcategory.SchoolID = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
                    SchoolID = Convert.ToInt32(Session["SchoolID"]);
                    // DataTable dtFields = schoolcategory.GetFieldsByCategory();
                    DataTable dtFields = schoolcategory.GetFieldsByCategoryStudentBusiness(SchoolID, CatId, Session["MLUICulture"].ToString());
                    ibtnAdd.Visible = true;



                    this.dTable.CellPadding = 2;
                    this.dTable.CellSpacing = 0;
                    this.dTable.Border = 0;

                    this.dTable.Width = "100%";
                    this.dTable.Attributes.Remove("class");

                    int tRows;
                    int tCells = 2;
                    int tCellsmod = Convert.ToInt32(dtFields.Rows.Count % tCells);

                    int tCellsquotient = Convert.ToInt32(dtFields.Rows.Count / tCells);
                    if (tCellsmod != 0)
                    {
                        tCellsquotient = tCellsquotient + 1;
                        DataRow dr = dtFields.NewRow();
                        dtFields.Rows.Add(dr);

                    }

                    for (tRows = 0; tRows < tCellsquotient; tRows++)
                    {
                        int L = 0;

                        if (dtFields.Rows.Count > 0 || dtFields.Rows.Count != 0)
                        {
                            this.dTRow = new HtmlTableRow();


                            for (tCells = 0; tCells < 2; tCells++)
                            {
                                this.dTCell = new HtmlTableCell();
                                this.dTCell2 = new HtmlTableCell();
                                dTCell2.Attributes.Add("class", "bevel_verline");
                                this.dTAdd = new HtmlTable();
                                this.dTAdd.CellPadding = 2;
                                this.dTAdd.CellSpacing = 0;
                                this.dTAdd.Border = 0;
                                this.dTAdd.Width = "100%";

                                //dTCell.Attributes.Add("class", "darkblue_content");


                                if (dtFields.Rows[L]["FieldName"].ToString() != "")
                                {
                                    dTCell.Align = "left";
                                    dTCell.VAlign = "top";


                                    this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + dtFields.Rows[L]["FieldName"].ToString() + "</div><div class=clear_m></div>";
                                    //StSuBL.FieldId = Convert.ToInt32(dtFields.Rows[L]["FieldId"]);
                                    int FieldIdPopul = Convert.ToInt32(dtFields.Rows[L]["FieldId"]);
                                    //schoolcategory.FieldId = Convert.ToInt32(dtFields.Rows[L]["FieldId"]);

                                    // DataTable dtaddressfields = schoolcategory.GetAddressFieldsByFieldId();
                                    DataTable dtaddressfields = schoolcategory.GetAddressFieldsByFieldIdStudentBusiness(SchoolID, FieldIdPopul, Session["MLUICulture"].ToString());

                                    int AddressTableRows;
                                    int AddressTableCells = 1;
                                    int AddressTableCellsmod = Convert.ToInt32(dtaddressfields.Rows.Count % AddressTableCells);

                                    int AddressTableCellsquotient = Convert.ToInt32(dtaddressfields.Rows.Count / AddressTableCells);
                                    if (AddressTableCellsmod != 0)
                                    {
                                        AddressTableCellsquotient = AddressTableCellsquotient + 1;
                                        int j = dtaddressfields.Rows.Count;

                                        DataRow dradd = dtaddressfields.NewRow();
                                        dtaddressfields.Rows.Add(dradd);

                                    }


                                    for (AddressTableRows = 0; AddressTableRows < AddressTableCellsquotient; AddressTableRows++)
                                    {
                                        AddressTableRows = 0;
                                        if (dtaddressfields.Rows.Count > 0 || dtaddressfields.Rows.Count != 0)
                                        {
                                            this.dTAddRow = new HtmlTableRow();

                                            for (AddressTableCells = 0; AddressTableCells < 1; AddressTableCells++)
                                            {

                                                this.dTAddCell = new HtmlTableCell();
                                                this.dTAddCell1 = new HtmlTableCell();
                                                this.dTAddCell2 = new HtmlTableCell();

                                                dTAddCell.Attributes.Add("class", "student_grid");
                                                this.dTAddCell.InnerHtml = "<div class='blue_bold'>" + dtaddressfields.Rows[AddressTableRows]["FieldName"].ToString() + "</div>";
                                                //dTCell.Align = "right";
                                                this.dTAddCell1.InnerText = " : ";
                                                dTAddCell.Align = "left";
                                                dTAddCell2.Align = "left";
                                                dTAddCell.VAlign = "top";
                                                dTAddCell1.VAlign = "top";
                                                dTAddCell2.VAlign = "top";
                                                dTAddCell.Attributes.Add("class", "width45");
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "1")
                                                {
                                                    TextBox txt = new TextBox();
                                                    HiddenField hdnFieldAddr = new HiddenField();
                                                    txt.CssClass = "textbox2";
                                                    txt.ID = "txt" + FieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();
                                                    this.dTAddCell2.Controls.Add(txt);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "2")
                                                {
                                                    CheckBoxList chk = new CheckBoxList();
                                                    HiddenField hdnFieldAddr = new HiddenField();
                                                    chk.ID = "chk" + FieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                                    chk.Items.Add("Same as Student's Home Address");
                                                    chk.RepeatDirection = RepeatDirection.Horizontal;
                                                    this.dTAddCell2.Controls.Add(chk);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "3")
                                                {
                                                    RadioButtonList rdb = new RadioButtonList();
                                                    HiddenField hdnFieldAddr = new HiddenField();

                                                    rdb.ID = "rdb" + FieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                                    rdb.RepeatDirection = RepeatDirection.Horizontal;
                                                    this.dTAddCell2.Controls.Add(rdb);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "4")
                                                {
                                                    DropDownList ddl = new DropDownList();
                                                    HiddenField hdnFieldAddr = new HiddenField();

                                                    ddl.ID = "ddl" + FieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                                    ddl.CssClass = "dropdown2";
                                                    if (dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "4" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "13" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "24" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "40")
                                                    {
                                                        //  categoryfields.populateState(ref ddl);
                                                        StuListCont.populateState(ref ddl);
                                                    }
                                                    if (dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "15" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "31")
                                                    {
                                                        // schoolcategory.PopulateContactRelationship(ref ddl);
                                                        StuListCont.PopulateContactRelationship(ref ddl);
                                                    }
                                                    this.dTAddCell2.Controls.Add(ddl);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "5")
                                                {
                                                    Label lbl = new Label();
                                                    HiddenField hdnFieldAddr = new HiddenField();

                                                    lbl.ID = "lbl" + FieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                                    this.dTAddCell2.Controls.Add(lbl);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }

                                                //*******************28/04/2010*******************
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "6")
                                                {
                                                    HiddenField hdnFieldAddr = new HiddenField();
                                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString()+"_"+ dtFields.Rows[L]["FieldId"].ToString();

                                                    var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                                                    control.ID = "uc" + FieldId;
                                                    this.dTAddCell2.Controls.Add(control);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                //************************************************


                                                this.dTAddRow.Controls.Add(dTAddCell);
                                                this.dTAddRow.Controls.Add(dTAddCell1);
                                                this.dTAddRow.Controls.Add(dTAddCell2);

                                                dtaddressfields.Rows.RemoveAt(0);
                                                FieldId++;

                                            }



                                            AddressTableRows = 0;
                                            dTAdd.Controls.Add(dTAddRow);


                                        }
                                        else
                                        {
                                            break;
                                        }

                                    }

                                    this.dTCell.Controls.Add(dTAdd);
                                    dtFields.Rows.RemoveAt(0);
                                    this.dTRow.Controls.Add(this.dTCell);
                                    if (tCells == 0)
                                    {
                                        this.dTRow.Controls.Add(this.dTCell2);
                                    }


                                }
                                this.dTable.Controls.Add(dTRow);
                            }

                        }
                        else
                        {
                            break;
                        }
                    }


                    string[] SessionTable = AddTableList.Split(';');
                    int SessionTableId = 1;
                    for (int i = 1; i < SessionTable.Length; i++)
                    {


                        this.dTRow = new HtmlTableRow();

                        for (tCells = 0; tCells < 2; tCells++)
                        {
                            string sessionTab = "Address" + SessionTableId.ToString();
                            DataTable myArrayDataFromSession = (DataTable)Session[sessionTab];
                            if (myArrayDataFromSession != null)
                            {
                                this.dTCell = new HtmlTableCell();
                                this.dTCell2 = new HtmlTableCell();
                                dTCell2.Attributes.Add("class", "bevel_verline");
                                this.dTAdd = new HtmlTable();
                                this.dTAdd.Width = "100%";
                                //dTCell.Attributes.Add("class", "darkblue_content");

                                string origtext = "Additional Contact";
                                string trantext = DTL.Translate(origtext, "en", langto);

                                //this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + "Additional Contact" + "</div><div class=clear_m></div>";
                                this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + trantext + "</div><div class=clear_m></div>";

                                int AddressTableRows = 0;
                                for (int m = 0; m < myArrayDataFromSession.Rows.Count; m++)
                                {

                                    this.dTAddRow = new HtmlTableRow();

                                    this.dTAddCell = new HtmlTableCell();
                                    this.dTAddCell1 = new HtmlTableCell();
                                    this.dTAddCell2 = new HtmlTableCell();
                                    this.dTAddCell.Align = "right";
                                    dTAddCell.Attributes.Add("class", "student_grid");

                                    if (myArrayDataFromSession.Rows[m]["FieldName"].ToString() != "")
                                    {

                                        this.dTAddCell.InnerHtml = "<div class='blue_bold'>" + myArrayDataFromSession.Rows[m]["FieldName"].ToString() + "</div>";
                                        this.dTAddCell1.InnerText = " : ";
                                    }
                                    dTAddCell.Align = "left";
                                    dTAddCell2.Align = "left";
                                    dTAddCell.VAlign = "top";
                                    dTAddCell1.VAlign = "top";
                                    dTAddCell2.VAlign = "top";
                                    dTAddCell.Attributes.Add("class", "width45");

                                    if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "1")
                                    {
                                        TextBox txt = new TextBox();
                                        HiddenField hdnFieldAddr = new HiddenField();
                                        txt.CssClass = "textbox2";
                                        txt.ID = "txt" + FieldId;
                                        hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                        hdnFieldAddr.Value = myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[AddressTableRows]["Default_Custom"].ToString();
                                        this.dTAddCell2.Controls.Add(txt);
                                        this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                    }
                                    if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "2")
                                    {
                                        CheckBoxList chk = new CheckBoxList();
                                        HiddenField hdnFieldAddr = new HiddenField();
                                        chk.ID = "chk" + FieldId;
                                        hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                        hdnFieldAddr.Value = myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[AddressTableRows]["Default_Custom"].ToString();
                                        chk.Items.Add("Same as Student's Home Address");
                                        chk.RepeatDirection = RepeatDirection.Horizontal;
                                        this.dTAddCell2.Controls.Add(chk);
                                        this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                    }
                                    if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "3")
                                    {
                                        RadioButtonList rdb = new RadioButtonList();
                                        HiddenField hdnFieldAddr = new HiddenField();
                                        rdb.ID = "rdb" + FieldId;
                                        hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                        hdnFieldAddr.Value = myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[AddressTableRows]["Default_Custom"].ToString();
                                        rdb.RepeatDirection = RepeatDirection.Horizontal;
                                        this.dTAddCell2.Controls.Add(rdb);
                                        this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                    }
                                    if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "4")
                                    {
                                        DropDownList ddl = new DropDownList();
                                        HiddenField hdnFieldAddr = new HiddenField();
                                        ddl.ID = "ddl" + FieldId;
                                        hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                        hdnFieldAddr.Value = myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[AddressTableRows]["Default_Custom"].ToString();
                                        ddl.CssClass = "dropdown2";
                                        if (myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() == "4" || myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() == "13" || myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() == "24" || myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() == "40")
                                        {
                                            // categoryfields.populateState(ref ddl);
                                            StuListCont.populateState(ref ddl);
                                        }

                                        if (myArrayDataFromSession.Rows[m]["FieldId"].ToString() == "4")
                                        {
                                            // categoryfields.populateState(ref ddl);
                                            StuListCont.populateState(ref ddl);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldId"].ToString() == "1")
                                        {
                                            // schoolcategory.PopulateContactRelationship(ref ddl);
                                            StuListCont.PopulateContactRelationship(ref ddl);
                                        }
                                        this.dTAddCell2.Controls.Add(ddl);
                                        this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                    }
                                    if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "5")
                                    {
                                        Label lbl = new Label();
                                        HiddenField hdnFieldAddr = new HiddenField();
                                        lbl.ID = "lbl" + FieldId;
                                        hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                        hdnFieldAddr.Value = myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[AddressTableRows]["Default_Custom"].ToString();
                                        this.dTAddCell2.Controls.Add(lbl);
                                        this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                    }

                                    //*******************28/04/2010*******************
                                    if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "6")
                                    {
                                        HiddenField hdnFieldAddr = new HiddenField();
                                        hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                        hdnFieldAddr.Value = myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[AddressTableRows]["Default_Custom"].ToString();

                                        var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                                        control.ID = "uc" + FieldId;
                                        this.dTAddCell2.Controls.Add(control);
                                        this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                    }
                                    //************************************************


                                    this.dTAddRow.Controls.Add(dTAddCell);
                                    this.dTAddRow.Controls.Add(dTAddCell1);
                                    this.dTAddRow.Controls.Add(dTAddCell2);
                                    // myArrayDataFromSession.Rows.RemoveAt(0);
                                    FieldId++;

                                    // }

                                    AddressTableRows = 0;
                                    dTAdd.Controls.Add(dTAddRow);

                                }


                                this.dTCell.Controls.Add(dTAdd);
                                this.dTRow.Controls.Add(this.dTCell);
                                if (tCells == 0)
                                {
                                    this.dTRow.Controls.Add(this.dTCell2);
                                }

                                this.dTable.Controls.Add(dTRow);

                            }

                            SessionTableId++;
                            // }
                        }

                    }

                    phAllFieldHolder.Controls.Add(dTable);

                }


                btnPrev.Visible = true;
                if (dt.Rows.Count == 1)
                {
                    btnSave.Visible = true;
                    btnNext.Visible = false;
                }
            }
        }
        catch (Exception ex)
        {
            string Error = ex.ToString();
        }

    }


    protected void StoreVaccinationFieldDataIntoDatatable()
    {

        DataTable SessiondtVaccination = (DataTable)Session["VaccinationForInsert"];
        if (SessiondtVaccination == null)
        {
            DataTable dtUserData = new DataTable();
            dtUserData.Columns.Add("Value");
            dtUserData.Columns.Add("FieldId");
            dtUserData.Columns.Add("FieldCatagory");


            foreach (var C in panel_Vaccination.Controls)
            {

                if (object.ReferenceEquals(C.GetType(), typeof(Repeater)))
                {

                    for (int i = 0; i <= rptrVaceField.Items.Count - 1; i++)
                    {
                        DataRow dr = dtUserData.NewRow();
                        TextBox txtfieldvalue = (TextBox)rptrVaceField.Items[i].FindControl("txt");
                        DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrVaceField.Items[i].FindControl("uc");
                       

                        HiddenField hdnFieldId = (HiddenField)rptrVaceField.Items[i].FindControl("hdnFieldId");
                        if (txtfieldvalue != null)
                        {
                            dr[0] = txtfieldvalue.Text.ToString();
                            dr[1] = hdnFieldId.Value.ToString();
                        }
                        if (uc != null)
                        {
                            dr[0] = uc.Value.ToString();
                            dr[1] = hdnFieldId.Value.ToString();
                        }

                        dtUserData.Rows.Add(dr);
                    }
                }
            }
            string SessionTableName = "VaccinationForInsert";
            Session.Add(SessionTableName, dtUserData);
        }
        else
        {


            foreach (var C in panel_Vaccination.Controls)
            {

                if (object.ReferenceEquals(C.GetType(), typeof(Repeater)))
                {

                    for (int i = 0; i <= rptrVaceField.Items.Count - 1; i++)
                    {
                        DataRow drvacc = SessiondtVaccination.NewRow();
                        TextBox txtfieldvalue = (TextBox)rptrVaceField.Items[i].FindControl("txt");
                        HiddenField hdnFieldId = (HiddenField)rptrVaceField.Items[i].FindControl("hdnFieldId");
                        if (txtfieldvalue != null)
                        {
                            drvacc[0] = txtfieldvalue.Text.ToString();
                            drvacc[1] = hdnFieldId.Value.ToString();
                        }

                        SessiondtVaccination.Rows.Add(drvacc);
                    }
                }
            }

            Session.Add("VaccinationForInsert", SessiondtVaccination);
        }
    }


    protected void btnPrev_Click(object sender, ImageClickEventArgs e)
    {
        try
        {

            StoreFieldDataIntoDatatable();

            int Count = dTable.Rows.Count;

            for (int k = Count - 1; k >= 0; k--)
            {

                this.dTable.Rows.RemoveAt(k);

            }
            if (hdnCatId.Value.ToString() == "5")
            {

                StoreMedicalInfoFieldDataIntoDatatable();
                //StoreVaccinationFieldDataIntoDatatable();
                DataStoreProgramForVaccination();

            }
            //storing enrollment info

            if (hdnCatId.Value.ToString() == "4")
            {

                StoreSchoolInfoFieldDataIntoDatatable();


            }


            PopulatePreviousFields();
            if (hdnCatId.Value.ToString() == "5")
            {

                PopulateMedicalInfoFieldData();
                //PopulateVaccinationFieldData();
                PopulateVccinationValue();

            }
            if (hdnCatId.Value.ToString() == "4")
            {

                PopulateSchoolInfoFieldData();


            }
            if (hdnCatId.Value.ToString() == "8")
            {

                PopulateGiftValue();
                PopulateSpecialValue();


            }
            PopulateFieldData();

        }
        catch (Exception ex)
        {
            string error = ex.ToString();
        }
    }


    protected void PopulatePreviousFields()
    {
        //EntryFormLayoutBL categoryfields = new EntryFormLayoutBL();
        OpenSISWCFServiceStudentFormLayoutClient categoryfields = new OpenSISWCFServiceStudentFormLayoutClient();
        try
        {
            //StudentBL STBL = new StudentBL();
            //StudentSetupBL StSuBL = new StudentSetupBL();
            //STBL.CatId = Convert.ToInt32(hdnCatId.Value);
            IopenSISServiceStudentClient STBL = new IopenSISServiceStudentClient();
            OpenSISWCFServiceStudentSetupClient StSuBL = new OpenSISWCFServiceStudentSetupClient();
            int CatId = Convert.ToInt32(hdnCatId.Value);
            //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);

            DataTable dt = STBL.GetPrevCategoryStudentBusiness(SchoolID, CatId);
            foreach (TreeNode tn in TreeView1.Nodes)
            {
                string t = tn.Value.Split(",".ToCharArray())[0];
                if (t == dt.Rows[0][0].ToString())
                {

                    tn.Selected = true;

                }

            }
            int FieldId = 0;
            if (dt.Rows[0][0].ToString() == "1")
            {

                divPhotoUpload.Style.Add("Display", "block");
                divOuter.Style.Add("Display", "block");
            }
            else
            {
                divPhotoUpload.Style.Add("Display", "none");
                divOuter.Style.Add("Display", "none");
            }

            if (dt.Rows.Count > 0)
            {
                if (dt.Rows[0][0].ToString() != "3")
                {
                    btnImmuAdd.Visible = false;
                    ibtnAlertAdd.Visible = false;
                    ibtnNursevisitAdd.Visible = false;
                    GVImmunization.Visible = false;
                    GVMedicalAlert.Visible = false;
                    GVNurseVisitRec.Visible = false;
                    ibtnVace.Visible = false;
                    rptrVaceField.Visible = false;
                    rptMedicalInfo.Visible = false;
                    TMInfo.Visible = false;

                    tblSchEnrInfo.Visible = false;
                    rptrSchlInfo.Visible = false;
                    gvEnrInfo.Visible = false;

                    tblProgram.Visible = false;

                    if (dt.Rows[0][0].ToString() != "5")
                    {
                        if (dt.Rows[0][0].ToString() != "4")
                        {
                            if (dt.Rows[0][0].ToString() != "8")
                            {
                                // StudentBL schoolcategory = new StudentBL();
                                IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
                                hdnCatId.Value = dt.Rows[0][0].ToString();
                                hdnInitialCatId.Value = hdnCatId.Value;
                                CatId = Convert.ToInt32(hdnCatId.Value);
                                //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                                SchoolID = Convert.ToInt32(Session["SchoolID"]);
                                // TreeView1.Nodes[Convert.ToInt32(hdnCatId.Value)].Selected = true;
                                string CatName = TreeView1.SelectedNode.Text.ToString();
                                //DataTable dtFields = schoolcategory.GetFieldsByCategory();
                                DataTable dtFields = schoolcategory.GetFieldsByCategoryStudentBusiness(SchoolID, CatId, Session["MLUICulture"].ToString());
                                ibtnAdd.Visible = false;

                                this.dTable.CellPadding = 2;
                                this.dTable.CellSpacing = 0;
                                this.dTable.Border = 0;
                                this.dTable.Width = "100%";
                                //this.dTable.Attributes.Add("class", "darkblue_content");

                                int tRows;
                                int tCells = 2;
                                int tCellsmod = Convert.ToInt32(dtFields.Rows.Count % tCells);

                                int tCellsquotient = Convert.ToInt32(dtFields.Rows.Count / tCells);
                                if (tCellsmod != 0)
                                {
                                    tCellsquotient = tCellsquotient + 1;
                                    int j = dtFields.Rows.Count;

                                    DataRow dr = dtFields.NewRow();
                                    dtFields.Rows.Add(dr);

                                }

                                this.dTRow = new HtmlTableRow();
                                this.dTCell = new HtmlTableCell();
                                this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + CatName.ToString() + "</div>";
                                this.dTCell.ColSpan = 6;
                                this.dTRow.Cells.Add(dTCell);
                                this.dTable.Rows.Insert(0, dTRow);

                                for (tRows = 0; tRows < tCellsquotient; tRows++)
                                {
                                    tRows = 0;
                                    if (dtFields.Rows.Count > 0 || dtFields.Rows.Count != 0)
                                    {

                                        this.dTRow = new HtmlTableRow();
                                        for (tCells = 0; tCells < 2; tCells++)
                                        {

                                            this.dTCell = new HtmlTableCell();
                                            this.dTCell1 = new HtmlTableCell();
                                            this.dTCell2 = new HtmlTableCell();
                                            dTCell.Attributes.Add("class", "student_grid");
                                            if (dtFields.Rows[tRows]["FieldName"].ToString() != "")
                                            {
                                                this.dTCell.InnerHtml = "<div class='blue_bold'>" + dtFields.Rows[tRows]["FieldName"].ToString() + "</div>";
                                                this.dTCell1.InnerText = ":";
                                            }
                                            dTCell.Align = "left";
                                            dTCell2.Align = "left";
                                            int FieldIdcatone = 0;
                                            if (dtFields.Rows[tRows]["FieldId"].ToString() != "")
                                            {
                                                // categoryfields.FieldId = Convert.ToInt32(dtFields.Rows[tRows]["FieldId"]);
                                                FieldIdcatone = Convert.ToInt32(dtFields.Rows[tRows]["FieldId"]);
                                            }
                                            if (dtFields.Rows[tRows]["FieldType"].ToString() == "1")
                                            {
                                                TextBox txt = new TextBox();
                                                HiddenField hdnFieldId = new HiddenField();
                                                txt.CssClass = "textbox2";
                                                txt.ID = "txt" + FieldId;
                                                hdnFieldId.ID = "hdn" + FieldId;
                                                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                                                this.dTCell2.Controls.Add(txt);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            if (dtFields.Rows[tRows]["FieldType"].ToString() == "2")
                                            {
                                                CheckBoxList chk = new CheckBoxList();
                                                HiddenField hdnFieldId = new HiddenField();
                                                chk.ID = "chk" + FieldId;
                                                hdnFieldId.ID = "hdn" + FieldId;
                                                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                                                chk.RepeatDirection = RepeatDirection.Horizontal;
                                                if (dtFields.Rows[tRows]["Default_Custom"].ToString() == "C")
                                                {
                                                    //  categoryfields.populatedynamicrchk(ref chk);
                                                    StuListCont.populatedynamicrchk(ref chk, FieldIdcatone);
                                                }
                                                this.dTCell2.Controls.Add(chk);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            if (dtFields.Rows[tRows]["FieldType"].ToString() == "3")
                                            {
                                                RadioButtonList rdb = new RadioButtonList();
                                                HiddenField hdnFieldId = new HiddenField();
                                                rdb.ID = "rdb" + FieldId;
                                                hdnFieldId.ID = "hdn" + FieldId;
                                                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                                                rdb.RepeatDirection = RepeatDirection.Horizontal;
                                                if (dtFields.Rows[tRows]["Default_Custom"].ToString() == "D")
                                                {
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 10)
                                                    {
                                                        // categoryfields.PopulateGender(ref rdb);
                                                        StuListCont.PopulateGender(ref rdb);
                                                    }
                                                }
                                                if (dtFields.Rows[tRows]["Default_Custom"].ToString() == "C")
                                                {
                                                    // categoryfields.populatedynamicrbtn(ref rdb);
                                                    StuListCont.populatedynamicrbtn(ref rdb, FieldIdcatone);
                                                }
                                                this.dTCell2.Controls.Add(rdb);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            if (dtFields.Rows[tRows]["FieldType"].ToString() == "4")
                                            {
                                                DropDownList ddl = new DropDownList();
                                                HiddenField hdnFieldId = new HiddenField();
                                                ddl.ID = "ddl" + FieldId;
                                                hdnFieldId.ID = "hdn" + FieldId;
                                                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                                                ddl.CssClass = "dropdown2";
                                                if (dtFields.Rows[tRows]["Default_Custom"].ToString() == "D")
                                                {
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 11)//ETHNICITY
                                                    {
                                                        //categoryfields.populateEthnicity(ref ddl);
                                                        //***********18/05/2010***************
                                                        StuListCont.populateEthnicity(ref ddl, Convert.ToInt32(Session["SchoolID"]));
                                                    }
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 15 || Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 16)//LANGUAGE
                                                    {
                                                        // categoryfields.populateLanguage(ref ddl);
                                                        StuListCont.populateLanguage(ref ddl);
                                                    }
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 18)//COUNTRY
                                                    {
                                                        // categoryfields.populateCountry(ref ddl);
                                                        StuListCont.populateCountry(ref ddl);
                                                    }
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 120)//START CONDITION
                                                    {
                                                        // vmlBL.populateCountry(ref ddl);
                                                        // categoryfields.PopulateEnrollCdn(ref ddl);
                                                        StuListCont.PopulateEnrollCdn(ref ddl);
                                                    }
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 110)//Calender
                                                    {

                                                        //STBL.populatecalender(ref ddl);
                                                        StuListCont.populatecalender(ref ddl, SchoolID);
                                                    }
                                                    //****************06/02/2010**************
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 210)//Religion
                                                    {


                                                        StuListCont.populateReligion(ref ddl);
                                                    }
                                                }
                                                if (dtFields.Rows[tRows]["Default_Custom"].ToString() == "C")
                                                {
                                                    // categoryfields.populatedynamicddl(ref ddl);
                                                    StuListCont.populatedynamicddl(ref ddl, FieldIdcatone);
                                                }
                                                this.dTCell2.Controls.Add(ddl);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            if (dtFields.Rows[tRows]["FieldType"].ToString() == "5")
                                            {
                                                Label lbl = new Label();
                                                HiddenField hdnFieldId = new HiddenField();
                                                lbl.ID = "lbl" + FieldId;
                                                hdnFieldId.ID = "hdn" + FieldId;
                                                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                                                //StudentBL stbl2 = new StudentBL();
                                                this.dTCell2.Controls.Add(lbl);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }


                                            //*******************28/04/2010*******************
                                            if (dtFields.Rows[tRows]["FieldType"].ToString() == "6")
                                            {

                                                HiddenField hdnFieldId = new HiddenField();
                                                hdnFieldId.ID = "hdn" + FieldId;
                                                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                                                Control control = new Control();
                                                 control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                                                control.ID = "uc" + FieldId;
                                                this.dTCell2.Controls.Add(control);
                                                this.dTCell2.Controls.Add(hdnFieldId);



                                            }
                                            //************************************************
                                            this.dTRow.Controls.Add(dTCell);
                                            this.dTRow.Controls.Add(dTCell1);
                                            this.dTRow.Controls.Add(dTCell2);
                                            dtFields.Rows.RemoveAt(0);
                                            tRows = 0;
                                            FieldId++;
                                        }
                                        this.dTable.Controls.Add(dTRow);

                                    }
                                    else
                                    {
                                        break;
                                    }
                                    // FieldId++;
                                }

                                this.dTRow = new HtmlTableRow();
                                this.dTCell = new HtmlTableCell();
                                this.dTCell.InnerHtml = "<div class='clear_small'></div>";
                                this.dTCell.ColSpan = 6;
                                this.dTRow.Cells.Add(dTCell);
                                this.dTable.Rows.Insert(tCellsquotient + 1, dTRow);

                                phAllFieldHolder.Controls.Add(dTable);
                            }
                            else
                            {
                                //Special and gifted in next
                                //StudentBL schoolcategory = new StudentBL();
                                IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
                                tblSchEnrInfo.Visible = false;
                                TMInfo.Visible = false;
                                tblProgram.Visible = true;
                                ibtnAdd.Visible = false;
                                hdnCatId.Value = dt.Rows[0][0].ToString();
                                CatId = Convert.ToInt32(hdnCatId.Value);
                                hdnInitialCatId.Value = hdnCatId.Value;


                            }
                        }
                        else
                        {
                            //enrollment populateprevious
                            DropDownList ddl = new DropDownList();
                            ibtnEnrInfo.Visible = true;
                            tblSchEnrInfo.Visible = true;
                            gvEnrInfo.Visible = true;
                            rptrSchlInfo.Visible = true;
                            IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
                            SchoolID = Convert.ToInt32(Session["SchoolID"]);

                            CatId = Convert.ToInt32(dt.Rows[0][0].ToString());
                            hdnCatId.Value = dt.Rows[0][0].ToString();
                            hdnInitialCatId.Value = hdnCatId.Value;
                            // DataTable dtschlinfo = schoolcategory.GetFieldsByCategory();
                            DataTable dtschlinfo = schoolcategory.GetFieldsByCategoryStudentBusiness(SchoolID, CatId, Session["MLUICulture"].ToString());
                            rptrSchlInfo.DataSource = dtschlinfo;
                            rptrSchlInfo.DataBind();

                            //for (int i = 0; i < dtschlinfo.Rows.Count; i++)
                            //{
                            //    if (Convert.ToInt32(dtschlinfo.Rows[i]["FieldId"].ToString()) == 110)//Calender
                            //    {

                            //        schoolcategory.populatecalender(ref ddl);
                            //    }
                            //}

                            DataTable SessiondtEnrol = (DataTable)Session["Enroltable"];
                            if (SessiondtEnrol != null)
                            {
                                gvEnrInfo.DataSource = SessiondtEnrol;
                                gvEnrInfo.DataBind();
                            }
                            else
                            {
                                DataTable dtEnrol = new DataTable();
                                dtEnrol.Columns.Add("AttStrtDate");
                                dtEnrol.Columns.Add("ExitDate");
                                dtEnrol.Columns.Add("ExitCode");
                                dtEnrol.Columns.Add("Exitreason");
                                dtEnrol.Columns.Add("StartCondition");
                                //added
                                dtEnrol.Columns.Add("ExitCodeValue");
                                DataRow dr = dtEnrol.NewRow();
                                dtEnrol.Rows.Add(dr);
                                gvEnrInfo.DataSource = dtEnrol;
                                gvEnrInfo.DataBind();
                            }

                        }
                    }
                    else
                    {

                        //  StudentBL schoolcategory = new StudentBL();
                        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
                        hdnCatId.Value = dt.Rows[0][0].ToString();
                        CatId = Convert.ToInt32(hdnCatId.Value);
                        hdnInitialCatId.Value = hdnCatId.Value;
                        btnImmuAdd.Visible = true;
                        ibtnAlertAdd.Visible = true;
                        ibtnNursevisitAdd.Visible = true;
                        GVImmunization.Visible = true;
                        GVMedicalAlert.Visible = true;
                        GVNurseVisitRec.Visible = true;
                        ibtnVace.Visible = true;
                        rptrVaceField.Visible = true;
                        rptMedicalInfo.Visible = true;
                        TMInfo.Visible = true;

                        DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
                        if (SessiondtImmu != null)
                        {
                            GVImmunization.DataSource = SessiondtImmu;
                            GVImmunization.DataBind();
                        }
                        else
                        {
                            DataTable dtImmu = new DataTable();
                            dtImmu.Columns.Add("Type");
                            dtImmu.Columns.Add("Date");
                            dtImmu.Columns.Add("Comment");
                            dtImmu.Columns.Add("Typevalue");
                            DataRow dr = dtImmu.NewRow();
                            dtImmu.Rows.Add(dr);
                            GVImmunization.DataSource = dtImmu;
                            GVImmunization.DataBind();
                        }
                        DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
                        if (SessiondtAlert != null)
                        {
                            GVMedicalAlert.DataSource = SessiondtAlert;
                            GVMedicalAlert.DataBind();
                        }
                        else
                        {
                            DataTable dtAlert = new DataTable();
                            dtAlert.Columns.Add("Alert");
                            DataRow dr = dtAlert.NewRow();
                            dtAlert.Rows.Add(dr);
                            GVMedicalAlert.DataSource = dtAlert;
                            GVMedicalAlert.DataBind();
                        }

                        DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
                        if (SessiondtNurseVisit != null)
                        {
                            GVNurseVisitRec.DataSource = SessiondtNurseVisit;
                            GVNurseVisitRec.DataBind();
                        }
                        else
                        {
                            DataTable dtNurseVisit = new DataTable();
                            dtNurseVisit.Columns.Add("Date");
                            dtNurseVisit.Columns.Add("TimeIn");
                            dtNurseVisit.Columns.Add("TimeOut");
                            dtNurseVisit.Columns.Add("Reason");
                            dtNurseVisit.Columns.Add("Result");
                            dtNurseVisit.Columns.Add("Comments");
                            DataRow dr = dtNurseVisit.NewRow();
                            dtNurseVisit.Rows.Add(dr);
                            GVNurseVisitRec.DataSource = dtNurseVisit;
                            GVNurseVisitRec.DataBind();
                        }

                        //DataTable dtVaccinationDetails = new DataTable();
                        //dtVaccinationDetails.Columns.Add("Vaccination_Code");
                        //dtVaccinationDetails.Columns.Add("Vaccination_Name");
                        //dtVaccinationDetails.Columns.Add("Vaccination_Date");
                        //dtVaccinationDetails.Columns.Add("Vaccination_Expiry_Date");
                        //dtVaccinationDetails.Columns.Add("Waiver");

                        //DataRow drvacc = dtVaccinationDetails.NewRow();
                        //dtVaccinationDetails.Rows.Add(drvacc);
                        //GVVccination.DataSource = dtVaccinationDetails;
                        //GVVccination.DataBind();

                        //PopulateVccinationGridview();

                        DataTable dtMedicalInfo = new DataTable();
                        // dtMedicalInfo = schoolcategory.GetMedicalInfoFields();
                        dtMedicalInfo = schoolcategory.GetMedicalInfoFieldsStudentBusiness(SchoolID, CatId);
                        rptMedicalInfo.DataSource = dtMedicalInfo;
                        rptMedicalInfo.DataBind();

                        //DataTable dtVcea = new DataTable();
                        //dtVcea = schoolcategory.GetVaccinationFields();
                        //rptrVaceField.DataSource = dtVcea;
                        //rptrVaceField.DataBind();

                    }
                }
                else
                {

                    tblProgram.Visible = false;
                    // StudentBL schoolcategory = new StudentBL();
                    IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
                    hdnCatId.Value = dt.Rows[0][0].ToString();
                    hdnInitialCatId.Value = hdnCatId.Value;
                    CatId = Convert.ToInt32(hdnCatId.Value);
                    //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                    //schoolcategory.SchoolID = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
                    // TreeView1.Nodes[Convert.ToInt32(hdnCatId.Value)].Selected = true;
                    // string CatName = TreeView1.SelectedNode.Text.ToString();
                    SchoolID = Convert.ToInt32(Session["SchoolID"]);
                    //DataTable dtFields = schoolcategory.GetFieldsByCategory();
                    DataTable dtFields = schoolcategory.GetFieldsByCategoryStudentBusiness(SchoolID, CatId, Session["MLUICulture"].ToString());
                    ibtnAdd.Visible = true;

                    tblSchEnrInfo.Visible = false;
                    rptrSchlInfo.Visible = false;
                    gvEnrInfo.Visible = false;

                    this.dTable.CellPadding = 2;
                    this.dTable.CellSpacing = 0;
                    this.dTable.Border = 0;
                    this.dTable.Width = "100%";
                    this.dTable.Attributes.Remove("class");
                    int tRows;
                    int tCells = 2;
                    int tCellsmod = Convert.ToInt32(dtFields.Rows.Count % tCells);

                    int tCellsquotient = Convert.ToInt32(dtFields.Rows.Count / tCells);
                    if (tCellsmod != 0)
                    {
                        tCellsquotient = tCellsquotient + 1;
                        DataRow dr = dtFields.NewRow();
                        dtFields.Rows.Add(dr);

                    }

                    for (tRows = 0; tRows < tCellsquotient; tRows++)
                    {
                        // tRows = 0;
                        int L = 0;
                        if (dtFields.Rows.Count > 0 || dtFields.Rows.Count != 0)
                        {

                            this.dTRow = new HtmlTableRow();

                            for (tCells = 0; tCells < 2; tCells++)
                            {

                                this.dTAdd = new HtmlTable();
                                this.dTAdd.CellPadding = 2;
                                this.dTAdd.CellSpacing = 0;
                                this.dTAdd.Border = 0;
                                this.dTAdd.Width = "100%";

                                this.dTCell = new HtmlTableCell();
                                this.dTCell2 = new HtmlTableCell();
                                dTCell2.Attributes.Add("class", "bevel_verline");

                                if (dtFields.Rows[L]["FieldName"].ToString() != "")
                                {
                                    dTCell.Align = "left";
                                    dTCell.VAlign = "top";
                                    //dTCell.Attributes.Add("class", "darkblue_content");
                                    this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + dtFields.Rows[L]["FieldName"].ToString() + "</div><div class=clear_m></div>";

                                    int FieldIdPopul = Convert.ToInt32(dtFields.Rows[L]["FieldId"]);
                                    //StSuBL.FieldId = Convert.ToInt32(dtFields.Rows[L]["FieldId"]);
                                    //schoolcategory.FieldId = Convert.ToInt32(dtFields.Rows[L]["FieldId"]);
                                    //int addressfieldcount = StSuBL.CheckDefaultAddressFieldCount();
                                    //if (addressfieldcount > 0)
                                    //{
                                    // DataTable dtaddressfields = schoolcategory.GetAddressFieldsByFieldId();
                                    DataTable dtaddressfields = schoolcategory.GetAddressFieldsByFieldIdStudentBusiness(SchoolID, FieldIdPopul, Session["MLUICulture"].ToString());
                                    //DataRow dra = dtaddressfields.NewRow();
                                    // dra["FieldName"] = dtFields.Rows[tRows]["FieldName"].ToString();
                                    // dtaddressfields.Rows.InsertAt(dra, 0);
                                    int AddressTableRows;
                                    int AddressTableCells = 1;
                                    int AddressTableCellsmod = Convert.ToInt32(dtaddressfields.Rows.Count % AddressTableCells);

                                    int AddressTableCellsquotient = Convert.ToInt32(dtaddressfields.Rows.Count / AddressTableCells);
                                    if (AddressTableCellsmod != 0)
                                    {
                                        AddressTableCellsquotient = AddressTableCellsquotient + 1;
                                        int j = dtaddressfields.Rows.Count;

                                        DataRow dradd = dtaddressfields.NewRow();
                                        dtaddressfields.Rows.Add(dradd);

                                    }


                                    for (AddressTableRows = 0; AddressTableRows < AddressTableCellsquotient; AddressTableRows++)
                                    {
                                        AddressTableRows = 0;
                                        if (dtaddressfields.Rows.Count > 0 || dtaddressfields.Rows.Count != 0)
                                        {
                                            this.dTAddRow = new HtmlTableRow();

                                            for (AddressTableCells = 0; AddressTableCells < 1; AddressTableCells++)
                                            {

                                                this.dTAddCell = new HtmlTableCell();
                                                this.dTAddCell1 = new HtmlTableCell();
                                                this.dTAddCell2 = new HtmlTableCell();
                                                this.dTAddCell.Align = "right";
                                                dTAddCell.Attributes.Add("class", "student_grid");

                                                this.dTAddCell.InnerHtml = "<div class='blue_bold'>" + dtaddressfields.Rows[AddressTableRows]["FieldName"].ToString() + "</div>";
                                                this.dTAddCell1.InnerText = " : ";
                                                dTAddCell.Align = "left";
                                                dTAddCell2.Align = "left";
                                                dTAddCell.VAlign = "top";
                                                dTAddCell1.VAlign = "top";
                                                dTAddCell2.VAlign = "top";
                                                dTAddCell.Attributes.Add("class", "width45");

                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "1")
                                                {
                                                    TextBox txt = new TextBox();
                                                    HiddenField hdnFieldAddr = new HiddenField();

                                                    txt.CssClass = "textbox2";
                                                    txt.ID = "txt" + FieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                                    this.dTAddCell2.Controls.Add(txt);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "2")
                                                {
                                                    CheckBoxList chk = new CheckBoxList();
                                                    HiddenField hdnFieldAddr = new HiddenField();

                                                    chk.ID = "chk" + FieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                                    chk.RepeatDirection = RepeatDirection.Horizontal;
                                                    this.dTAddCell2.Controls.Add(chk);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "3")
                                                {
                                                    RadioButtonList rdb = new RadioButtonList();
                                                    HiddenField hdnFieldAddr = new HiddenField();

                                                    rdb.ID = "rdb" + FieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                                    rdb.RepeatDirection = RepeatDirection.Horizontal;
                                                    this.dTAddCell2.Controls.Add(rdb);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "4")
                                                {
                                                    DropDownList ddl = new DropDownList();
                                                    HiddenField hdnFieldAddr = new HiddenField();

                                                    ddl.ID = "ddl" + FieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                                    ddl.CssClass = "dropdown2";
                                                    if (dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "4" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "13" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "24" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "40")
                                                    {
                                                        //categoryfields.populateState(ref ddl);
                                                        StuListCont.populateState(ref ddl);
                                                    }
                                                    if (dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "15" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "31")
                                                    {
                                                        //schoolcategory.PopulateContactRelationship(ref ddl);
                                                        StuListCont.PopulateContactRelationship(ref ddl);
                                                    }
                                                    this.dTAddCell2.Controls.Add(ddl);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "5")
                                                {
                                                    Label lbl = new Label();
                                                    HiddenField hdnFieldAddr = new HiddenField();

                                                    lbl.ID = "lbl" + FieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();
                                                    this.dTAddCell2.Controls.Add(lbl);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }

                                                //*******************28/04/2010*******************
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "6")
                                                {
                                                    HiddenField hdnFieldAddr = new HiddenField();
                                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString()+"_"+ dtFields.Rows[L]["FieldId"].ToString();

                                                    var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                                                    control.ID = "uc" + FieldId;
                                                    this.dTAddCell2.Controls.Add(control);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                //************************************************

                                                this.dTAddRow.Controls.Add(dTAddCell);
                                                this.dTAddRow.Controls.Add(dTAddCell1);
                                                this.dTAddRow.Controls.Add(dTAddCell2);
                                                dtaddressfields.Rows.RemoveAt(0);
                                                FieldId++;

                                            }



                                            AddressTableRows = 0;
                                            dTAdd.Controls.Add(dTAddRow);

                                        }
                                        else
                                        {
                                            break;
                                        }
                                        // FieldId++;
                                    }


                                    // }

                                    this.dTCell.Controls.Add(dTAdd);
                                    dtFields.Rows.RemoveAt(0);
                                    this.dTRow.Controls.Add(this.dTCell);

                                    if (tCells == 0)
                                    {
                                        this.dTRow.Controls.Add(this.dTCell2);
                                    }

                                }
                            }

                            this.dTable.Controls.Add(dTRow);
                        }
                        else
                        {
                            break;
                        }
                    }


                    string[] SessionTable = AddTableList.Split(';');
                    int SessionTableId = 1;
                    for (int i = 1; i < SessionTable.Length; i++)
                    {


                        this.dTRow = new HtmlTableRow();

                        for (tCells = 0; tCells < 2; tCells++)
                        {
                            string sessionTab = "Address" + SessionTableId.ToString();
                            DataTable myArrayDataFromSession = (DataTable)Session[sessionTab];
                            if (myArrayDataFromSession != null)
                            {
                                this.dTCell = new HtmlTableCell();
                                this.dTCell2 = new HtmlTableCell();

                                dTCell2.Attributes.Add("class", "bevel_verline");

                                this.dTAdd = new HtmlTable();
                                this.dTAdd.Width = "100%";
                                //dTCell.Attributes.Add("class", "darkblue_content");
                                string origtext = "Additional Contact";
                                string trantext = DTL.Translate(origtext, "en", langto);

                                // this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + "Additional Contact" + "</div><div class=clear_m></div>";
                                this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + trantext + "</div><div class=clear_m></div>";

                                int AddressTableRows = 0;
                                for (int m = 0; m < myArrayDataFromSession.Rows.Count; m++)
                                {

                                    this.dTAddRow = new HtmlTableRow();

                                    this.dTAddCell = new HtmlTableCell();
                                    this.dTAddCell1 = new HtmlTableCell();
                                    this.dTAddCell2 = new HtmlTableCell();
                                    this.dTAddCell.Align = "right";
                                    dTAddCell.Attributes.Add("class", "student_grid");
                                    if (myArrayDataFromSession.Rows[m]["FieldName"].ToString() != "")
                                    {
                                        this.dTAddCell.InnerHtml = "<div class='blue_bold'>" + myArrayDataFromSession.Rows[m]["FieldName"].ToString() + "</div>";
                                        this.dTAddCell1.InnerText = " : ";
                                    }
                                    dTAddCell.Align = "left";
                                    dTAddCell2.Align = "left";
                                    dTAddCell.VAlign = "top";
                                    dTAddCell1.VAlign = "top";
                                    dTAddCell2.VAlign = "top";
                                    dTAddCell.Attributes.Add("class", "width45");

                                    if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "1")
                                    {
                                        TextBox txt = new TextBox();
                                        HiddenField hdnFieldAddr = new HiddenField();
                                        txt.CssClass = "textbox2";
                                        txt.ID = "txt" + FieldId;
                                        hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                        hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                        this.dTAddCell2.Controls.Add(txt);
                                        this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                    }
                                    if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "2")
                                    {
                                        CheckBoxList chk = new CheckBoxList();
                                        HiddenField hdnFieldAddr = new HiddenField();
                                        chk.ID = "chk" + FieldId;
                                        hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                        hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                        chk.Items.Add("Same as Student's Home Address");
                                        chk.RepeatDirection = RepeatDirection.Horizontal;
                                        this.dTAddCell2.Controls.Add(chk);
                                        this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                    }
                                    if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "3")
                                    {
                                        RadioButtonList rdb = new RadioButtonList();
                                        HiddenField hdnFieldAddr = new HiddenField();
                                        rdb.ID = "rdb" + FieldId;
                                        hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                        hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                        rdb.RepeatDirection = RepeatDirection.Horizontal;
                                        this.dTAddCell2.Controls.Add(rdb);
                                        this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                    }
                                    if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "4")
                                    {
                                        DropDownList ddl = new DropDownList();
                                        HiddenField hdnFieldAddr = new HiddenField();
                                        ddl.ID = "ddl" + FieldId;
                                        hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                        hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                        ddl.CssClass = "dropdown2";
                                        if (myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() == "4" || myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() == "13" || myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() == "24" || myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() == "40")
                                        {
                                            //categoryfields.populateState(ref ddl);
                                            StuListCont.populateState(ref ddl);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldId"].ToString() == "4")
                                        {
                                            // categoryfields.populateState(ref ddl);
                                            StuListCont.populateState(ref ddl);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldId"].ToString() == "1")
                                        {
                                            // schoolcategory.PopulateContactRelationship(ref ddl);
                                            StuListCont.PopulateContactRelationship(ref ddl);
                                        }
                                        this.dTAddCell2.Controls.Add(ddl);
                                        this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                    }
                                    if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "5")
                                    {
                                        Label lbl = new Label();
                                        HiddenField hdnFieldAddr = new HiddenField();
                                        lbl.ID = "lbl" + FieldId;
                                        hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                        hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                        this.dTAddCell2.Controls.Add(lbl);
                                        this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                    }

                                    //*******************28/04/2010*******************
                                    if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "6")
                                    {
                                        HiddenField hdnFieldAddr = new HiddenField();
                                        hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                        hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();

                                        var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                                        control.ID = "uc" + FieldId;
                                        this.dTAddCell2.Controls.Add(control);
                                        this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                    }
                                    //************************************************

                                    this.dTAddRow.Controls.Add(dTAddCell);
                                    this.dTAddRow.Controls.Add(dTAddCell1);
                                    this.dTAddRow.Controls.Add(dTAddCell2);
                                    // myArrayDataFromSession.Rows.RemoveAt(0);
                                    FieldId++;

                                    // }

                                    AddressTableRows = 0;
                                    dTAdd.Controls.Add(dTAddRow);

                                }


                                this.dTCell.Controls.Add(dTAdd);
                                this.dTRow.Controls.Add(this.dTCell);
                                if (tCells == 0)
                                {
                                    this.dTRow.Controls.Add(this.dTCell2);
                                }

                                this.dTable.Controls.Add(dTRow);

                            }

                            SessionTableId++;
                            // }
                        }

                    }


                    phAllFieldHolder.Controls.Add(dTable);

                }



                btnNext.Visible = true;
                btnSave.Visible = false;
                if (dt.Rows.Count == 1)
                {
                    btnPrev.Visible = false;
                }
                else
                {
                    btnPrev.Visible = true;
                }
            }
        }
        catch { }

    }


    protected void btnAdditionalConSave_Click(object sender, EventArgs e)
    {
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        hdnInitialCatId.Value = hdnCatId.Value;
        int CatId = Convert.ToInt32(hdnCatId.Value);
        //// ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
        int SchoolID = Convert.ToInt32(Session["SchoolID"]);
        int HomeFieldId = 152;
        DataTable dtFields = schoolcategory.PopulateAdditionalFieldStudentBusiness(SchoolID, HomeFieldId, Session["MLUICulture"].ToString());
        string SessionTableName = "Address" + AddSet++.ToString();
        AddTableList = SessionTableName + ";" + AddTableList;
        //hdnAddFieldValue.Value = "AddressValue" + AddSet++.ToString();
        //**********************************************************
        
       Session.Add(SessionTableName, dtFields);
       PopulateAddressFieldData();
       StoreFieldDataIntoDatatable();

       PopulateInSelectedNodeChange();
       PopulateFieldData();
      
       ModalPopupExtender1.Enabled = false;


       schoolcategory.Close();
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            //StudentBL StudentAdd = new StudentBL();
            IopenSISServiceStudentClient StudentAdd = new IopenSISServiceStudentClient();
            //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);
            DataTable dt = StudentAdd.GetSchoolSpecificCategoryStudentBusiness(SchoolID.ToString(), Session["MLUICulture"].ToString());
            int StdId = StudentAdd.StudentAddStudentBusiness(SchoolID);
            int StudentID = StdId;
            int FieldId = 0;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i][0].ToString() != "3")
                {
                    if (dt.Rows[i][0].ToString() != "5")
                    {

                        if (dt.Rows[i][0].ToString() != "4")
                        {
                            if (dt.Rows[i][0].ToString() != "8")
                            {
                                string SessionTable = dt.Rows[i][0].ToString();
                                DataTable myArrayDataFromSession = (DataTable)Session[SessionTable];
                                if (myArrayDataFromSession != null)
                                {
                                    for (int j = 0; j < myArrayDataFromSession.Rows.Count; j++)
                                    {

                                        if (myArrayDataFromSession.Rows[j][1].ToString() != "" && myArrayDataFromSession.Rows[j][4].ToString() != "")
                                        {
                                            StudentID = StdId;
                                            string FieldCategory = myArrayDataFromSession.Rows[j][2].ToString();
                                            FieldId = Convert.ToInt32(myArrayDataFromSession.Rows[j][1]);
                                            string Value = myArrayDataFromSession.Rows[j][0].ToString();
                                            int CatId = Convert.ToInt32(dt.Rows[i][0]);
                                            StudentAdd.InsertIntoStudentDetailsStudentBusiness(StudentID, FieldCategory, FieldId, Value, CatId);
                                            FieldCategory = myArrayDataFromSession.Rows[j][5].ToString();
                                            FieldId = Convert.ToInt32(myArrayDataFromSession.Rows[j][4]);
                                            Value = myArrayDataFromSession.Rows[j][3].ToString();
                                            StudentAdd.InsertIntoStudentDetailsStudentBusiness(StudentID, FieldCategory, FieldId, Value, CatId);
                                        }
                                        else
                                        {
                                            if (myArrayDataFromSession.Rows[j][1].ToString() != "")
                                            {
                                                StudentID = StdId;
                                                string FieldCategory = myArrayDataFromSession.Rows[j][2].ToString();
                                                FieldId = Convert.ToInt32(myArrayDataFromSession.Rows[j][1]);
                                                string Value = myArrayDataFromSession.Rows[j][0].ToString();
                                                int CatId = Convert.ToInt32(dt.Rows[i][0]);
                                                StudentAdd.InsertIntoStudentDetailsStudentBusiness(StudentID, FieldCategory, FieldId, Value, CatId);
                                            }
                                        }

                                    }
                                }
                            }
                            else
                            //********** if (dt.Rows[i][0].ToString() != "8")****************************
                            {
                                DataTable SessiondtspecialEdu = (DataTable)Session["SpecialEduForInsert"];

                                if (SessiondtspecialEdu != null)
                                {

                                    for (int Specrowid = 0; Specrowid <= SessiondtspecialEdu.Rows.Count - 1; Specrowid++)
                                    {
                                        string Value = SessiondtspecialEdu.Rows[Specrowid][0].ToString();
                                        FieldId = Convert.ToInt32(SessiondtspecialEdu.Rows[Specrowid][1].ToString());
                                        SchoolID = Convert.ToInt32(Session["SchoolID"]);
                                        StudentID = StdId;
                                        int CatId = Convert.ToInt32(SessiondtspecialEdu.Rows[Specrowid][4].ToString());
                                        StudentAdd.InsertSpecialValueStudentBusiness(FieldId, CatId, StudentID, Value, SchoolID);

                                    }

                                }

                                DataTable SessiondtGift = (DataTable)Session["SpecialGiftForInsert"];

                                if (SessiondtGift != null)
                                {

                                    for (int Giftrowid = 0; Giftrowid <= SessiondtGift.Rows.Count - 1; Giftrowid++)
                                    {
                                        string Value = SessiondtGift.Rows[Giftrowid][0].ToString();
                                        FieldId = Convert.ToInt32(SessiondtGift.Rows[Giftrowid][1].ToString());
                                        SchoolID = Convert.ToInt32(Session["SchoolID"]);
                                        StudentID = StdId;
                                        int CatId = Convert.ToInt32(SessiondtGift.Rows[Giftrowid][4].ToString()); ;
                                        StudentAdd.InsertgiftedValueStudentBusiness(FieldId, CatId, Value, SchoolID, StudentID);

                                    }

                                }



                            }
                            //********** if (dt.Rows[i][0].ToString() != "8")end else****************************
                        }
                        else
                        //************** [if (dt.Rows[i][0].ToString() != "4")else]***************
                        {
                            string PrevSessionTable = "SchoolInfo";
                            DataTable SchoolInfoDataFromSession = (DataTable)Session["SchoolInfo"];
                            if (SchoolInfoDataFromSession != null)
                            {
                                for (int Srowid = 0; Srowid <= SchoolInfoDataFromSession.Rows.Count - 1; Srowid++)
                                {


                                    StudentID = StdId;
                                    string FieldCategory = SchoolInfoDataFromSession.Rows[Srowid]["Default_Custom"].ToString();
                                    FieldId = Convert.ToInt32(SchoolInfoDataFromSession.Rows[Srowid]["FieldId"]);
                                    string Value = SchoolInfoDataFromSession.Rows[Srowid]["Value"].ToString();
                                    int CatId = Convert.ToInt32(SchoolInfoDataFromSession.Rows[Srowid]["Category"]);
                                    StudentAdd.InsertIntoStudentDetailsStudentBusiness(StudentID, FieldCategory, FieldId, Value, CatId);

                                }
                            }
                            DataTable EnrollmentInfoDataFromSession = (DataTable)Session["Enroltable"];
                            if (EnrollmentInfoDataFromSession != null)
                            {
                                for (int Enrow = 0; Enrow < EnrollmentInfoDataFromSession.Rows.Count; Enrow++)
                                {



                                    StudentID = StdId;
                                    SchoolID = Convert.ToInt32(Session["SchoolID"]);
                                    string EnrAttStartdate = EnrollmentInfoDataFromSession.Rows[Enrow]["AttStrtDate"].ToString();
                                    string EnrExitDate = EnrollmentInfoDataFromSession.Rows[Enrow]["ExitDate"].ToString();
                                    string EnrExitCode = EnrollmentInfoDataFromSession.Rows[Enrow]["ExitCodeValue"].ToString();
                                    string EnrExitreason = EnrollmentInfoDataFromSession.Rows[Enrow]["Exitreason"].ToString();
                                    string EnrStartCondition = EnrollmentInfoDataFromSession.Rows[Enrow]["StartCondition"].ToString();
                                    //ddlFullYear = (DropDownList)Page.Master.FindControl("ddlFullYear");
                                    // string s = Session["MP"].ToString();
                                    // int EnrSchyrId = Convert.ToInt32(Session["MP"]);
                                    int EnrSchyrId = Convert.ToInt32(Session["FullYear"]);

                                    if (EnrSchyrId == 0)
                                    {
                                        EnrSchyrId = 2;
                                    }
                                    StudentAdd.InsertEnrollmentStudentBusiness(EnrAttStartdate, EnrExitDate, StudentID, SchoolID, EnrSchyrId, EnrExitCode, EnrExitreason, EnrStartCondition);
                                    Session["Enroltable"] = null;
                                }


                            }

                        }
                        //************** [if (dt.Rows[i][0].ToString() != "4")end else]***************
                    }
                    else
                    //****************if (dt.Rows[i][0].ToString() != "5")[else]**************
                    {
                        string PrevSessionTable = "MedicalInfo";
                        DataTable MedicalInfoDataFromSession = (DataTable)Session[PrevSessionTable];
                        if (MedicalInfoDataFromSession != null)
                        {

                            for (int Mrowid = 0; Mrowid <= MedicalInfoDataFromSession.Rows.Count - 1; Mrowid++)
                            {
                                StudentID = StdId;
                                string Value = MedicalInfoDataFromSession.Rows[Mrowid][0].ToString();
                                int MedInfoId = Convert.ToInt32(MedicalInfoDataFromSession.Rows[Mrowid][1].ToString());
                                StudentAdd.InsertIntoStudentMedicalInformationDetailsStudentBusiness(StudentID, SchoolID, Value, MedInfoId);

                            }
                        }

                        DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
                        if (SessiondtImmu != null)
                        {
                            for (int MInfoid = 0; MInfoid <= SessiondtImmu.Rows.Count - 1; MInfoid++)
                            {

                                int MedInfoType = Convert.ToInt32(SessiondtImmu.Rows[MInfoid][3].ToString());
                                string MedInfoDate = SessiondtImmu.Rows[MInfoid][1].ToString();
                                string Comments = SessiondtImmu.Rows[MInfoid][2].ToString();
                                StudentAdd.InsertIntoStudentImmunizationDetailsStudentBusiness(MedInfoType, MedInfoDate, Comments, SchoolID, StudentID, FieldId);



                            }
                        }

                        DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
                        if (SessiondtAlert != null)
                        {
                            for (int Alertid = 0; Alertid <= SessiondtAlert.Rows.Count - 1; Alertid++)
                            {


                                string Value = SessiondtAlert.Rows[Alertid][0].ToString();
                                int LifeThreatInd = 0;
                                int MedAlertActId = 0;
                                StudentAdd.InsertIntoStudentMedicalAlertStudentBusiness(StudentID, MedAlertActId, Value, LifeThreatInd);


                            }
                        }

                        DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
                        if (SessiondtNurseVisit != null)
                        {
                            for (int Nurserowid = 0; Nurserowid <= SessiondtNurseVisit.Rows.Count - 1; Nurserowid++)
                            {

                                string NurseVisitDate = SessiondtNurseVisit.Rows[Nurserowid][0].ToString();
                                string NurseVisitTimeIn = SessiondtNurseVisit.Rows[Nurserowid][1].ToString();
                                string NurseVisitTimeOut = SessiondtNurseVisit.Rows[Nurserowid][2].ToString();
                                string NurseVisitReason = SessiondtNurseVisit.Rows[Nurserowid][3].ToString();
                                string NurseVisitResult = SessiondtNurseVisit.Rows[Nurserowid][4].ToString();
                                string Comments = SessiondtNurseVisit.Rows[Nurserowid][5].ToString();
                                StudentAdd.InsertIntoStudentNurseVisitRecordDetailsStudentBusiness(NurseVisitDate, NurseVisitTimeIn, NurseVisitTimeOut, NurseVisitReason, NurseVisitResult, Comments, StudentID, SchoolID);


                            }
                        }



                        DataTable VaccinationDataFromSession = (DataTable)Session["VaccinationForInsert"];

                        if (VaccinationDataFromSession != null)
                        {

                            for (int Vaccrowid = 0; Vaccrowid <= VaccinationDataFromSession.Rows.Count - 1; Vaccrowid++)
                            {
                                string Value = VaccinationDataFromSession.Rows[Vaccrowid][0].ToString();
                                FieldId = Convert.ToInt32(VaccinationDataFromSession.Rows[Vaccrowid][1].ToString());
                                StudentAdd.InsertIntoStudentVaccinationRecordDetailsStudentBusiness(StudentID, SchoolID, Value, FieldId);

                            }

                        }


                    }

                    //****************if (dt.Rows[i][0].ToString() != "5")[end else]**************
                }
                else
                {
                    //************* if (dt.Rows[i][0].ToString() != "3")*************************
                    string SessionTable = dt.Rows[i][0].ToString();
                    DataTable myArrayDataFromSession = (DataTable)Session[SessionTable];
                    if (myArrayDataFromSession != null)
                    {
                        int k = 1;
                        for (int j = 0; j < myArrayDataFromSession.Rows.Count; j++)
                        {

                            if (myArrayDataFromSession.Rows[j][1].ToString() != "")
                            {
                                if (myArrayDataFromSession.Rows[j][2].ToString() == "D")
                                {
                                    StudentID = StdId;
                                    string FieldCategory = myArrayDataFromSession.Rows[j][2].ToString();
                                    int AddId = Convert.ToInt32(myArrayDataFromSession.Rows[j][1]);
                                    FieldId = Convert.ToInt32(myArrayDataFromSession.Rows[j][4]);
                                    string Value = myArrayDataFromSession.Rows[j][0].ToString();
                                    int CatId = Convert.ToInt32(dt.Rows[i][0]);
                                    StudentAdd.InsertIntoStudentAdddressDetailsStudentBusiness(StudentID, AddId, Value, FieldId, CatId, SchoolID);
                                }
                                else
                                {
                                    StudentID = StdId;
                                    string FieldCategory = myArrayDataFromSession.Rows[j][2].ToString();
                                    FieldId = Convert.ToInt32(myArrayDataFromSession.Rows[j][1]);
                                    string Value = myArrayDataFromSession.Rows[j][0].ToString();
                                    int Set = Convert.ToInt32(myArrayDataFromSession.Rows[j][3]);
                                    int CatId = Convert.ToInt32(dt.Rows[i][0]);
                                    int ContSetId = k++;
                                    StudentAdd.InsertIntoStudentAdditionalContactStudentBusiness(CatId, StudentID, FieldId, Value, Set, SchoolID, ContSetId);
                                    // int CheckConSet = StudentAdd.CountSetFields();
                                    // if (CheckConSet == k)
                                    //  {
                                    //   k = 1;
                                    //  }
                                }
                            }
                        }
                    }

                }

                //************* if (dt.Rows[i][0].ToString() != "3") else end*************************
            }

            //*********************************photo save(saikat-14/10/2009)***********************************
            string PhotoUrl = Session["StudentImage"].ToString().Replace("~", "..");
            StudentAdd.SaveStudentPhotoStudentBusiness(StudentID, SchoolID, PhotoUrl);
            string uploadedimage = "~/Garbage Image/" + Session["WorkingImage"].ToString();
            File.Delete(Server.MapPath(uploadedimage));
            Session["WorkingImage"] = null;
            Session["StudentImage"] = null;
            //*********************************photo save(saikat-14/10/2009)***********************************


            StudentAdd.Close();


        }
        catch (Exception ex)
        {
            string EX = ex.ToString();
        }
        finally
        {
            //StudentBL StudentAdd = new StudentBL();
            IopenSISServiceStudentClient StudentAdd = new IopenSISServiceStudentClient();
            //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);
            DataTable dt = StudentAdd.GetSchoolSpecificCategoryStudentBusiness(SchoolID.ToString(), Session["MLUICulture"].ToString());
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Session[dt.Rows[i]["Cat_Id"].ToString()] = null;
            }

            string[] SessionTable = AddTableList.Split(';');
            int SessionTableId = 1;
            for (int i = 1; i < SessionTable.Length; i++)
            {
                string sessionTab = "Address" + SessionTableId.ToString();
                Session[sessionTab] = null;
            }
            Session["SchoolInfo"] = null;
            Session["Enroltable"] = null;
            Session["MedicalInfo"] = null;
            Session["ImmuTable"] = null;
            Session["AlertTable"] = null;
            Session["NurseVisitTable"] = null;
            Session["VaccinationForInsert"] = null;
        }


        Response.Redirect("StudentInfo.aspx");

    }
    protected void btnImmuAdd_Click(object sender, ImageClickEventArgs e)
    {

        //StudentBL schoolcategory = new StudentBL();
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
        if (SessiondtImmu != null)
        {
            GVImmunization.DataSource = SessiondtImmu;
            GVImmunization.DataBind();
        }
        else
        {
            DataTable dtImmuDetails = new DataTable();
            dtImmuDetails.Columns.Add("Type");
            dtImmuDetails.Columns.Add("Date");
            dtImmuDetails.Columns.Add("Comment");
            dtImmuDetails.Columns.Add("Typevalue");
            DataRow dr = dtImmuDetails.NewRow();
            dtImmuDetails.Rows.Add(dr);
            GVImmunization.DataSource = dtImmuDetails;
            GVImmunization.DataBind();

        }
        DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
        if (SessiondtAlert != null)
        {
            GVMedicalAlert.DataSource = SessiondtAlert;
            GVMedicalAlert.DataBind();
        }
        else
        {
            DataTable dtAlertDetails = new DataTable();
            dtAlertDetails.Columns.Add("Alert");

            DataRow dr = dtAlertDetails.NewRow();
            dtAlertDetails.Rows.Add(dr);
            GVMedicalAlert.DataSource = dtAlertDetails;
            GVMedicalAlert.DataBind();


        }
        DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
        if (SessiondtNurseVisit != null)
        {
            GVNurseVisitRec.DataSource = SessiondtNurseVisit;
            GVNurseVisitRec.DataBind();
        }
        else
        {
            DataTable dtNurseVisitDetails = new DataTable();
            dtNurseVisitDetails.Columns.Add("Date");
            dtNurseVisitDetails.Columns.Add("TimeIn");
            dtNurseVisitDetails.Columns.Add("TimeOut");
            dtNurseVisitDetails.Columns.Add("Reason");
            dtNurseVisitDetails.Columns.Add("Result");
            dtNurseVisitDetails.Columns.Add("Comments");
            DataRow dr = dtNurseVisitDetails.NewRow();
            dtNurseVisitDetails.Rows.Add(dr);
            GVNurseVisitRec.DataSource = dtNurseVisitDetails;
            GVNurseVisitRec.DataBind();

        }

        //***************29/04/2010**************

        OpenSISWCFServiceInstallationClient InstallBL = new OpenSISWCFServiceInstallationClient();

        SISInstall SISInstall = new SISInstall();
        DataTable dtDateFormat = InstallBL.getdateformat();
        if (dtDateFormat.Rows.Count > 0)
        {
            SISInstall.CalenderDateFormat = dtDateFormat.Rows[0][0].ToString();
        }

        CalenderPicker.Format = SISInstall.CalenderDateFormat.ToString().Trim();
        CalNursVistDate.Format = SISInstall.CalenderDateFormat.ToString().Trim();


        //PopulateVccinationGridview();

        //DataTable dtMedicalInfo = new DataTable();
        //dtMedicalInfo = schoolcategory.GetMedicalInfoFields();
        //rptMedicalInfo.DataSource = dtMedicalInfo;
        //rptMedicalInfo.DataBind();

        //DataTable dtVcea = new DataTable();
        //dtVcea = schoolcategory.GetVaccinationFields();
        //rptrVaceField.DataSource = dtVcea;
        //rptrVaceField.DataBind();

        PopulateMedicalInfoFieldData();
        PopulateVaccinationFieldData();

        ModalPopupExtender2.Enabled = true;
        ModalPopupExtender2.Show();


    }

    protected void ibtnAlertAdd_Click(object sender, ImageClickEventArgs e)
    {

        //StudentBL schoolcategory = new StudentBL();
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
        if (SessiondtImmu != null)
        {
            GVImmunization.DataSource = SessiondtImmu;
            GVImmunization.DataBind();
        }
        else
        {
            DataTable dtImmuDetails = new DataTable();
            dtImmuDetails.Columns.Add("Type");
            dtImmuDetails.Columns.Add("Date");
            dtImmuDetails.Columns.Add("Comment");
            dtImmuDetails.Columns.Add("Typevalue");
            DataRow dr = dtImmuDetails.NewRow();
            dtImmuDetails.Rows.Add(dr);
            GVImmunization.DataSource = dtImmuDetails;
            GVImmunization.DataBind();

        }
        DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
        if (SessiondtAlert != null)
        {
            GVMedicalAlert.DataSource = SessiondtAlert;
            GVMedicalAlert.DataBind();
        }
        else
        {
            DataTable dtAlertDetails = new DataTable();
            dtAlertDetails.Columns.Add("Alert");
            DataRow dr = dtAlertDetails.NewRow();
            dtAlertDetails.Rows.Add(dr);
            GVMedicalAlert.DataSource = dtAlertDetails;
            GVMedicalAlert.DataBind();


        }
        DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
        if (SessiondtNurseVisit != null)
        {
            GVNurseVisitRec.DataSource = SessiondtNurseVisit;
            GVNurseVisitRec.DataBind();
        }
        else
        {
            DataTable dtNurseVisitDetails = new DataTable();
            dtNurseVisitDetails.Columns.Add("Date");
            dtNurseVisitDetails.Columns.Add("TimeIn");
            dtNurseVisitDetails.Columns.Add("TimeOut");
            dtNurseVisitDetails.Columns.Add("Reason");
            dtNurseVisitDetails.Columns.Add("Result");
            dtNurseVisitDetails.Columns.Add("Comments");
            DataRow dr = dtNurseVisitDetails.NewRow();
            dtNurseVisitDetails.Rows.Add(dr);
            GVNurseVisitRec.DataSource = dtNurseVisitDetails;
            GVNurseVisitRec.DataBind();

        }

        PopulateMedicalInfoFieldData();
        //PopulateVccinationGridview();

        //DataTable dtMedicalInfo = new DataTable();
        //dtMedicalInfo = schoolcategory.GetMedicalInfoFields();
        //rptMedicalInfo.DataSource = dtMedicalInfo;
        //rptMedicalInfo.DataBind();

        //DataTable dtVcea = new DataTable();
        //dtVcea = schoolcategory.GetVaccinationFields();
        //rptrVaceField.DataSource = dtVcea;
        //rptrVaceField.DataBind();

        ModalPopupExtender3.Enabled = true;
        ModalPopupExtender3.Show();
        btnPrev.Visible = true;


    }

    protected void ibtnNursevisitAdd_Click(object sender, ImageClickEventArgs e)
    {

        // StudentBL schoolcategory = new StudentBL();
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
        if (SessiondtImmu != null)
        {
            GVImmunization.DataSource = SessiondtImmu;
            GVImmunization.DataBind();
        }
        else
        {
            DataTable dtImmuDetails = new DataTable();
            dtImmuDetails.Columns.Add("Type");
            dtImmuDetails.Columns.Add("Date");
            dtImmuDetails.Columns.Add("Comment");
            dtImmuDetails.Columns.Add("Typevalue");
            DataRow dr = dtImmuDetails.NewRow();
            dtImmuDetails.Rows.Add(dr);
            GVImmunization.DataSource = dtImmuDetails;
            GVImmunization.DataBind();

        }
        DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
        if (SessiondtAlert != null)
        {
            GVMedicalAlert.DataSource = SessiondtAlert;
            GVMedicalAlert.DataBind();
        }
        else
        {
            DataTable dtAlertDetails = new DataTable();
            dtAlertDetails.Columns.Add("Alert");
            DataRow dr = dtAlertDetails.NewRow();
            dtAlertDetails.Rows.Add(dr);
            GVMedicalAlert.DataSource = dtAlertDetails;
            GVMedicalAlert.DataBind();


        }
        DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
        if (SessiondtNurseVisit != null)
        {
            GVNurseVisitRec.DataSource = SessiondtNurseVisit;
            GVNurseVisitRec.DataBind();
        }
        else
        {
            DataTable dtNurseVisitDetails = new DataTable();
            dtNurseVisitDetails.Columns.Add("Date");
            dtNurseVisitDetails.Columns.Add("TimeIn");
            dtNurseVisitDetails.Columns.Add("TimeOut");
            dtNurseVisitDetails.Columns.Add("Reason");
            dtNurseVisitDetails.Columns.Add("Result");
            dtNurseVisitDetails.Columns.Add("Comments");
            DataRow dr = dtNurseVisitDetails.NewRow();
            dtNurseVisitDetails.Rows.Add(dr);
            GVNurseVisitRec.DataSource = dtNurseVisitDetails;
            GVNurseVisitRec.DataBind();

        }

        PopulateMedicalInfoFieldData();
        //PopulateVccinationGridview();

        //DataTable dtMedicalInfo = new DataTable();
        //dtMedicalInfo = schoolcategory.GetMedicalInfoFields();
        //rptMedicalInfo.DataSource = dtMedicalInfo;
        //rptMedicalInfo.DataBind();

        //DataTable dtVcea = new DataTable();
        //dtVcea = schoolcategory.GetVaccinationFields();
        //rptrVaceField.DataSource = dtVcea;
        //rptrVaceField.DataBind();

        ModalPopupExtender4.Enabled = true;
        ModalPopupExtender4.Show();
        btnPrev.Visible = true;


    }

    protected void ibtnVace_Click(object sender, ImageClickEventArgs e)
    {

        //StudentBL schoolcategory = new StudentBL();
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
        if (SessiondtImmu != null)
        {
            GVImmunization.DataSource = SessiondtImmu;
            GVImmunization.DataBind();
        }
        else
        {
            DataTable dtImmuDetails = new DataTable();
            dtImmuDetails.Columns.Add("Type");
            dtImmuDetails.Columns.Add("Date");
            dtImmuDetails.Columns.Add("Comment");
            dtImmuDetails.Columns.Add("Typevalue");
            DataRow dr = dtImmuDetails.NewRow();
            dtImmuDetails.Rows.Add(dr);
            GVImmunization.DataSource = dtImmuDetails;
            GVImmunization.DataBind();

        }
        DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
        if (SessiondtAlert != null)
        {
            GVMedicalAlert.DataSource = SessiondtAlert;
            GVMedicalAlert.DataBind();
        }
        else
        {
            DataTable dtAlertDetails = new DataTable();
            dtAlertDetails.Columns.Add("Alert");
            DataRow dr = dtAlertDetails.NewRow();
            dtAlertDetails.Rows.Add(dr);
            GVMedicalAlert.DataSource = dtAlertDetails;
            GVMedicalAlert.DataBind();


        }
        DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
        if (SessiondtNurseVisit != null)
        {
            GVNurseVisitRec.DataSource = SessiondtNurseVisit;
            GVNurseVisitRec.DataBind();
        }
        else
        {
            DataTable dtNurseVisitDetails = new DataTable();
            dtNurseVisitDetails.Columns.Add("Date");
            dtNurseVisitDetails.Columns.Add("TimeIn");
            dtNurseVisitDetails.Columns.Add("TimeOut");
            dtNurseVisitDetails.Columns.Add("Reason");
            dtNurseVisitDetails.Columns.Add("Result");
            dtNurseVisitDetails.Columns.Add("Comments");
            DataRow dr = dtNurseVisitDetails.NewRow();
            dtNurseVisitDetails.Rows.Add(dr);
            GVNurseVisitRec.DataSource = dtNurseVisitDetails;
            GVNurseVisitRec.DataBind();

        }

        //DataTable dtVaccinationDetails = new DataTable();
        //dtVaccinationDetails.Columns.Add("Vaccination_Code");
        //dtVaccinationDetails.Columns.Add("Vaccination_Name");
        //dtVaccinationDetails.Columns.Add("Vaccination_Date");
        //dtVaccinationDetails.Columns.Add("Vaccination_Expiry_Date");
        //dtVaccinationDetails.Columns.Add("Waiver");

        //DataRow drvacc = dtVaccinationDetails.NewRow();
        //dtVaccinationDetails.Rows.Add(drvacc);
        //GVVccination.DataSource = dtVaccinationDetails;
        //GVVccination.DataBind();

        PopulateMedicalInfoFieldData();
        //PopulateVccinationGridview();

        DataTable dtVcea = new DataTable();

        int scholid = 0;
        int catid = 0;
        dtVcea = schoolcategory.GetVaccinationFieldsStudentBusiness(scholid, catid);
        // dtVcea = schoolcategory.PopulateSpecialField();
        rptrVaceField.DataSource = dtVcea;
        rptrVaceField.DataBind();

        ModalPopupExtender5.Enabled = true;
        ModalPopupExtender5.Show();
        btnPrev.Visible = true;

    }

    protected void btnImmuSave_Click(object sender, EventArgs e)
    {
        try
        {

            //StudentBL schoolcategory = new StudentBL();
            IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
            DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
            if (SessiondtImmu == null)
            {
                DataTable dtImmuDetails = new DataTable();
                dtImmuDetails.Columns.Add("Type");
                dtImmuDetails.Columns.Add("Date");
                dtImmuDetails.Columns.Add("Comment");
                dtImmuDetails.Columns.Add("Typevalue");


                DataRow dr = dtImmuDetails.NewRow();

                dr["Type"] = ddlImmunaization.SelectedItem.Text;
                dr["Date"] = txtdate.Text.ToString();
                dr["Comment"] = txtcomments.Text.ToString();
                dr["Typevalue"] = ddlImmunaization.SelectedItem.Value;

                dtImmuDetails.Rows.Add(dr);
                GVImmunization.DataSource = dtImmuDetails;
                GVImmunization.DataBind();
                Session.Add("ImmuTable", dtImmuDetails);

            }
            else
            {
                DataRow dr = SessiondtImmu.NewRow();
                dr["Type"] = ddlImmunaization.SelectedItem.Text;
                dr["Date"] = txtdate.Text.ToString();
                dr["Comment"] = txtcomments.Text.ToString();
                dr["Typevalue"] = ddlImmunaization.SelectedItem.Value;

                SessiondtImmu.Rows.Add(dr);
                GVImmunization.DataSource = SessiondtImmu;
                GVImmunization.DataBind();
                Session.Add("ImmuTable", SessiondtImmu);

            }

            //  PopulateMedicalInfoFieldData();
            //PopulateVccinationGridview();

            ModalPopupExtender2.Enabled = false;
            //DataTable dtMedicalInfo = new DataTable();
            //dtMedicalInfo = schoolcategory.GetMedicalInfoFields();
            //rptMedicalInfo.DataSource = dtMedicalInfo;
            //rptMedicalInfo.DataBind();

            //DataTable dtVcea = new DataTable();
            //dtVcea = schoolcategory.GetVaccinationFields();
            //rptrVaceField.DataSource = dtVcea;
            //rptrVaceField.DataBind();
            //btnPrev.Visible = true;
        }
        catch (Exception ex)
        {
            string error = ex.ToString();
        }
    }

    protected void btnAlertSave_Click(object sender, EventArgs e)
    {
        try
        {
            // StudentBL schoolcategory = new StudentBL();
            IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
            DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
            if (SessiondtAlert == null)
            {
                DataTable dtAlertDetails = new DataTable();
                dtAlertDetails.Columns.Add("Alert");
                DataRow dr = dtAlertDetails.NewRow();


                dr["Alert"] = txtAlerts.Text.ToString();

                dtAlertDetails.Rows.Add(dr);


                GVMedicalAlert.DataSource = dtAlertDetails;
                GVMedicalAlert.DataBind();
                Session.Add("AlertTable", dtAlertDetails);
            }
            else
            {
                DataRow dr = SessiondtAlert.NewRow();
                dr["Alert"] = txtAlerts.Text.ToString();

                SessiondtAlert.Rows.Add(dr);
                GVMedicalAlert.DataSource = SessiondtAlert;
                GVMedicalAlert.DataBind();
                Session.Add("AlertTable", SessiondtAlert);

            }

            PopulateMedicalInfoFieldData();
            //PopulateVccinationGridview();
            //DataTable dtMedicalInfo = new DataTable();
            //dtMedicalInfo = schoolcategory.GetMedicalInfoFields();
            //rptMedicalInfo.DataSource = dtMedicalInfo;
            //rptMedicalInfo.DataBind();

            //DataTable dtVcea = new DataTable();
            //dtVcea = schoolcategory.GetVaccinationFields();
            //rptrVaceField.DataSource = dtVcea;
            //rptrVaceField.DataBind();
            //btnPrev.Visible = true;
        }
        catch (Exception ex)
        {
            string error = ex.ToString();
        }
    }

    protected void btnNurseVisitSave_Click(object sender, EventArgs e)
    {
        try
        {
            //StudentBL schoolcategory = new StudentBL();
            IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
            DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
            if (SessiondtNurseVisit == null)
            {
                DataTable dtNurseVisitDetails = new DataTable();
                dtNurseVisitDetails.Columns.Add("Date");
                dtNurseVisitDetails.Columns.Add("TimeIn");
                dtNurseVisitDetails.Columns.Add("TimeOut");
                dtNurseVisitDetails.Columns.Add("Reason");
                dtNurseVisitDetails.Columns.Add("Result");
                dtNurseVisitDetails.Columns.Add("Comments");



                DataRow dr = dtNurseVisitDetails.NewRow();

                dr["Date"] = txtNurseVisitDate.Text.ToString();
                dr["TimeIn"] = txtTimeIn.Text.ToString();
                dr["TimeOut"] = txtTimeOut.Text.ToString();
                dr["Reason"] = txtReason.Text.ToString();
                dr["Result"] = txtResult.Text.ToString();
                dr["Comments"] = txtNurseComments.Text.ToString();

                dtNurseVisitDetails.Rows.Add(dr);


                GVNurseVisitRec.DataSource = dtNurseVisitDetails;
                GVNurseVisitRec.DataBind();
                Session.Add("NurseVisitTable", dtNurseVisitDetails);
            }
            else
            {
                DataRow dr = SessiondtNurseVisit.NewRow();

                dr["Date"] = txtNurseVisitDate.Text.ToString();
                dr["TimeIn"] = txtTimeIn.Text.ToString();
                dr["TimeOut"] = txtTimeOut.Text.ToString();
                dr["Reason"] = txtReason.Text.ToString();
                dr["Result"] = txtResult.Text.ToString();
                dr["Comments"] = txtNurseComments.Text.ToString();

                SessiondtNurseVisit.Rows.Add(dr);
                GVNurseVisitRec.DataSource = SessiondtNurseVisit;
                GVNurseVisitRec.DataBind();
                Session.Add("NurseVisitTable", SessiondtNurseVisit);

            }

            PopulateMedicalInfoFieldData();
            //PopulateVccinationGridview();

            //DataTable dtMedicalInfo = new DataTable();
            //dtMedicalInfo = schoolcategory.GetMedicalInfoFields();
            //rptMedicalInfo.DataSource = dtMedicalInfo;
            //rptMedicalInfo.DataBind();

            //DataTable dtVcea = new DataTable();
            //dtVcea = schoolcategory.GetVaccinationFields();
            //rptrVaceField.DataSource = dtVcea;
            //rptrVaceField.DataBind();
            //btnPrev.Visible = true;
        }
        catch (Exception ex)
        {
            string error = ex.ToString();
        }


    }

    protected void btnvcciCancel_Click(object sender, EventArgs e)
    {
        ModalPopupExtender5.Enabled = false;
        ModalPopupExtender5.Show();
        btnPrev.Visible = true;
    }

    protected void btnvcciSave_Click(object sender, EventArgs e)
    {
        //DataTable SessiondtVaccination = (DataTable)Session["VaccinationForGrid"];
        //if (SessiondtVaccination == null)
        //{
        //    DataTable dtVaccinationDetails = new DataTable();
        //    dtVaccinationDetails.Columns.Add("Vaccination_Code");
        //    dtVaccinationDetails.Columns.Add("Vaccination_Name");
        //    dtVaccinationDetails.Columns.Add("Vaccination_Date");
        //    dtVaccinationDetails.Columns.Add("Vaccination_Expiry_Date");
        //    dtVaccinationDetails.Columns.Add("Waiver");

        //    foreach (var C in panel_Vaccination.Controls)
        //    {

        //        if (object.ReferenceEquals(C.GetType(), typeof(Repeater)))
        //        {

        //            Repeater rptrVaceField = ((Repeater)C);
        //            DataRow drvacc = dtVaccinationDetails.NewRow();
        //            for (int i = 0; i <= rptrVaceField.Items.Count - 1; i++)
        //            {
        //                TextBox txtfieldvalue = (TextBox)rptrVaceField.Items[i].FindControl("txt");

        //                if (txtfieldvalue != null)
        //                {
        //                    drvacc[i] = txtfieldvalue.Text.ToString();
        //                }

        //                DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrSchlInfo.Items[i].FindControl("uc");
        //                if (uc != null)
        //                {
        //                    drvacc[i] = uc.Value.ToString();

        //                }


        //            }
        //            dtVaccinationDetails.Rows.Add(drvacc);
        //        }
        //    }

        //    GVVccination.DataSource = dtVaccinationDetails;
        //    GVVccination.DataBind();
        //    Session.Add("VaccinationForGrid", dtVaccinationDetails);
        //}
        //else
        //{
        //    DataRow drvacc = SessiondtVaccination.NewRow();
        //    foreach (var C in panel_Vaccination.Controls)
        //    {

        //        if (object.ReferenceEquals(C.GetType(), typeof(Repeater)))
        //        {

        //            Repeater rptrVaceField = ((Repeater)C);

        //            for (int i = 0; i <= rptrVaceField.Items.Count - 1; i++)
        //            {
        //                TextBox txtfieldvalue = (TextBox)rptrVaceField.Items[i].FindControl("txt");

        //                if (txtfieldvalue != null)
        //                {
        //                    drvacc[i] = txtfieldvalue.Text.ToString();
        //                }

        //                DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrVaceField.Items[i].FindControl("uc");
        //                if (uc != null)
        //                {
        //                    drvacc[i] = uc.Value.ToString();

        //                }


        //            }

        //        }
        //    }
        //    SessiondtVaccination.Rows.Add(drvacc);
        //    GVVccination.DataSource = SessiondtVaccination;
        //    GVVccination.DataBind();
        //    Session.Add("VaccinationForGrid", SessiondtVaccination);
        //}

        //StoreVaccinationFieldDataIntoDatatable();


        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        DataTable SessiondtVaccination = (DataTable)Session["VaccinationForInsert"];
        if (SessiondtVaccination == null)
        {
            DataTable dtUserData = new DataTable();
            dtUserData.Columns.Add("Value");
            dtUserData.Columns.Add("FieldId");

            dtUserData.Columns.Add("FieldType");
            foreach (var C in panel_Vaccination.Controls)
            {

                if (object.ReferenceEquals(C.GetType(), typeof(Repeater)))
                {

                    for (int i = 0; i <= rptrVaceField.Items.Count - 1; i++)
                    {
                        DataRow dr = dtUserData.NewRow();
                        TextBox txtfieldvalue = (TextBox)rptrVaceField.Items[i].FindControl("txt");
                        DropDownList ddlfieldvalue = (DropDownList)rptrVaceField.Items[i].FindControl("ddl");
                        RadioButtonList rdbfieldvalue = (RadioButtonList)rptrVaceField.Items[i].FindControl("rdb");
                        //TextBox txtfieldvalue = (TextBox)rptrSpecial.Items[i].FindControl("txt");
                        HiddenField hdnFieldId = (HiddenField)rptrVaceField.Items[i].FindControl("hdnFieldId");
                        HiddenField hdnFieldType = (HiddenField)rptrVaceField.Items[i].FindControl("hdnFieldType");
                        if (txtfieldvalue != null)
                        {
                            //dr[0] = txtfieldvalue.Text.ToString();
                            //dr[1] = hdnFieldId.Value.ToString();
                            dr["Value"] = txtfieldvalue.Text.ToString();
                            dr["FieldId"] = hdnFieldId.Value.ToString();
                            dr["FieldType"] = hdnFieldType.Value.ToString();
                        }
                        //*********************01/05/2010**************
                        DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrVaceField.Items[i].FindControl("uc");
                        if (uc != null)
                        {

                            dr["Value"] = uc.Value.ToString();
                            dr["FieldId"] = hdnFieldId.Value.ToString();
                            dr["FieldType"] = hdnFieldType.Value.ToString();
                        }
                        if (ddlfieldvalue != null)
                        {


                            if (ddlfieldvalue.SelectedIndex != -1)
                            {
                                //dr[0] = ddlfieldvalue.SelectedItem.Value.ToString();
                                //dr[1] = hdnFieldId.Value.ToString();
                                dr["Value"] = ddlfieldvalue.SelectedItem.Value.ToString();
                                dr["FieldId"] = hdnFieldId.Value.ToString();
                                dr["FieldType"] = hdnFieldType.Value.ToString(); ;
                            }

                        }

                        if (rdbfieldvalue != null)
                        {
                            for (int r = 0; r < rdbfieldvalue.Items.Count; r++)
                            {
                                if (rdbfieldvalue.Items[r].Selected)
                                {
                                    //dr[0] = rdbfieldvalue.SelectedItem.Value.ToString();

                                    //dr[1] = hdnFieldId.Value.ToString();
                                    dr["Value"] = rdbfieldvalue.SelectedItem.Value.ToString();
                                    dr["FieldId"] = hdnFieldId.Value.ToString();
                                    dr["FieldType"] = hdnFieldType.Value.ToString(); ;
                                }

                            }

                        }
                        //dr["Cat_Id"] = hdnCatId.Value.ToString();

                        dtUserData.Rows.Add(dr);
                    }
                }
            }







            string SessionTableName = "VaccinationForInsert";
            Session.Add(SessionTableName, dtUserData);

            rptrVccination.DataSource = dtUserData;
            rptrVccination.DataBind();
        }
        else
        {

            foreach (var C in panel_Vaccination.Controls)
            {

                if (object.ReferenceEquals(C.GetType(), typeof(Repeater)))
                {
                    Repeater rptrVaceField = ((Repeater)C);
                    for (int i = 0; i <= rptrVaceField.Items.Count - 1; i++)
                    {
                        DataRow dr = SessiondtVaccination.NewRow();
                        TextBox txtfieldvalue = (TextBox)rptrVaceField.Items[i].FindControl("txt");
                        DropDownList ddlfieldvalue = (DropDownList)rptrVaceField.Items[i].FindControl("ddl");
                        RadioButtonList rdbfieldvalue = (RadioButtonList)rptrVaceField.Items[i].FindControl("rdb");
                        //TextBox txtfieldvalue = (TextBox)rptrSpecial.Items[i].FindControl("txt");
                        HiddenField hdnFieldId = (HiddenField)rptrVaceField.Items[i].FindControl("hdnFieldId");
                        HiddenField hdnFieldType = (HiddenField)rptrVaceField.Items[i].FindControl("hdnFieldType");

                        if (txtfieldvalue != null)
                        {
                            //dr[0] = txtfieldvalue.Text.ToString();
                            //dr[1] = hdnFieldId.Value.ToString();
                            dr["Value"] = txtfieldvalue.Text.ToString();
                            dr["FieldId"] = hdnFieldId.Value.ToString();
                            dr["FieldType"] = hdnFieldType.Value.ToString();
                        }
                        //*********************01/05/2010**************
                        DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrVaceField.Items[i].FindControl("uc");
                        if (uc != null)
                        {

                            dr["Value"] = uc.Value.ToString();
                            dr["FieldId"] = hdnFieldId.Value.ToString();
                            dr["FieldType"] = hdnFieldType.Value.ToString();
                        }
                        if (ddlfieldvalue != null)
                        {


                            if (ddlfieldvalue.SelectedIndex != -1)
                            {
                                //dr[0] = ddlfieldvalue.SelectedItem.Value.ToString();
                                //dr[1] = hdnFieldId.Value.ToString();
                                dr["Value"] = ddlfieldvalue.SelectedItem.Value.ToString();
                                dr["FieldId"] = hdnFieldId.Value.ToString();
                                dr["FieldType"] = hdnFieldType.Value.ToString(); ;
                            }

                        }

                        if (rdbfieldvalue != null)
                        {
                            for (int r = 0; r < rdbfieldvalue.Items.Count; r++)
                            {
                                if (rdbfieldvalue.Items[r].Selected)
                                {
                                    //dr[0] = rdbfieldvalue.SelectedItem.Value.ToString();

                                    //dr[1] = hdnFieldId.Value.ToString();
                                    dr["Value"] = rdbfieldvalue.SelectedItem.Value.ToString();
                                    dr["FieldId"] = hdnFieldId.Value.ToString();
                                    dr["FieldType"] = hdnFieldType.Value.ToString(); ;
                                }

                            }

                        }

                        // dr[4] = hdnCatId.Value.ToString();
                        // dr["Cat_Id"] = hdnCatId.Value.ToString();

                        SessiondtVaccination.Rows.Add(dr);
                    }
                }
            }


            Session.Add("VaccinationForInsert", SessiondtVaccination);
            rptrVccination.DataSource = SessiondtVaccination;
            rptrVccination.DataBind();
        }


    }

    protected void ibtnEnrInfo_Click(object sender, ImageClickEventArgs e)
    {

        rptrSchlInfo.Visible = true;
        // StudentBL schoolcategory = new StudentBL();
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        DataTable SessiondtEnrol = (DataTable)Session["Enroltable"];
        if (SessiondtEnrol != null)
        {
            gvEnrInfo.DataSource = SessiondtEnrol;
            gvEnrInfo.DataBind();
        }
        else
        {
            DataTable dtEnrol = new DataTable();
            dtEnrol.Columns.Add("AttStrtDate");
            dtEnrol.Columns.Add("ExitDate");
            dtEnrol.Columns.Add("ExitCode");
            dtEnrol.Columns.Add("Exitreason");
            dtEnrol.Columns.Add("StartCondition");
            //added
            dtEnrol.Columns.Add("ExitCodeValue");
            DataRow dr = dtEnrol.NewRow();
            dtEnrol.Rows.Add(dr);
            gvEnrInfo.DataSource = dtEnrol;
            gvEnrInfo.DataBind();
        }


        // PopulateVccinationGridview();
        //schoolcategory.PopulateEnrollCdn(ref ddlExitCode);
        
        //SchoolBL schoolAdd = new SchoolBL();
        OpenSISWCFServiceInstallationClient InstallBL = new OpenSISWCFServiceInstallationClient();

        SISInstall SISInstall = new SISInstall();
        DataTable dtDateFormat = InstallBL.getdateformat();
        if (dtDateFormat.Rows.Count > 0)
        {
            SISInstall.CalenderDateFormat = dtDateFormat.Rows[0][0].ToString();
        }

        CalDobDate.Format = SISInstall.CalenderDateFormat.ToString().Trim();
        CalendarExtender1.Format = SISInstall.CalenderDateFormat.ToString().Trim();


        StuListCont.PopulateEnrollCdn(ref ddlExitCode);


        PopulateSchoolInfoFieldData();
        // PopulateVaccinationFieldData();

        ModalPopupExtender6.Enabled = true;
        ModalPopupExtender6.Show();


    }

    protected void rptrSchlInfo_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        try
        {
            // ViewFormLayoutBL vmlBL = new ViewFormLayoutBL();
            HiddenField hdnFieldType = (HiddenField)e.Item.FindControl("hdnFieldType");
            HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
            HtmlControl maindiv = (HtmlControl)e.Item.FindControl("maindiv");
            HiddenField hdnDefCus = (HiddenField)e.Item.FindControl("hdnDefCus");
            if (hdnDefCus.Value.ToString().Trim() == "D")
            {
                if (hdnFieldType.Value.ToString() == "1")
                {
                    TextBox txt = new TextBox();
                    txt.ID = "txt";
                    txt.Width = 150;
                    txt.CssClass = "textbox2";
                    maindiv.Controls.Add(txt);
                    //e.Item.Controls.Add(txt);
                    // string t = txt.ID.ToString();

                }
                if (hdnFieldType.Value.ToString() == "2")
                {
                    CheckBoxList chk = new CheckBoxList();
                    chk.ID = "chk";
                    chk.RepeatDirection = RepeatDirection.Horizontal;
                    maindiv.Controls.Add(chk);
                }
                if (hdnFieldType.Value.ToString() == "3")
                {
                    //RadioButtonList rdb = new RadioButtonList();
                    //rdb.ID = "rdb";
                    //vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
                    //if (Convert.ToInt32(hdnFieldId.Value) == 10)
                    //{
                    //    vmlBL.PopulateGender(ref rdb);
                    //}
                    //rdb.RepeatDirection = RepeatDirection.Horizontal;
                    //maindiv.Controls.Add(rdb);
                }
                if (hdnFieldType.Value.ToString() == "4")
                {
                    DropDownList ddl = new DropDownList();
                    ddl.ID = "ddl";
                    ddl.Width = 155;
                    ddl.CssClass = "textbox_date";
                    maindiv.Controls.Add(ddl);
                    if (Convert.ToInt32(hdnFieldId.Value.ToString()) == 110)//Calender
                    {

                        // StudentBL schoolcategory = new StudentBL();
                        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
                        int SchoolID = Convert.ToInt32(Session["SchoolID"]
);
                        StuListCont.populatecalender(ref ddl, SchoolID);
                    }

                }
                if (hdnFieldType.Value.ToString() == "5")
                {
                    Label lbl = new Label();
                    lbl.ID = "lbl";
                    // StudentBL stbl2 = new StudentBL();
                    maindiv.Controls.Add(lbl);
                }
                if (hdnFieldType.Value.ToString() == "3")
                {
                    RadioButtonList rdb = new RadioButtonList();
                    rdb.ID = "rdb";
                    rdb.RepeatDirection = RepeatDirection.Horizontal;
                    //  StudentBL stbl2 = new StudentBL();
                    maindiv.Controls.Add(rdb);
                    if (Convert.ToInt32(hdnFieldId.Value.ToString()) == 106)//Calender
                    {

                        // StudentBL schoolcategory = new StudentBL();
                        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
                        int SchoolID = Convert.ToInt32(Session["SchoolID"]);
                        StuListCont.PopulateYesNo(ref rdb);
                    }
                }

                //****************************1/5/2010***********
                if (hdnFieldType.Value.ToString() == "6")
                {
                    var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                   
                    control.ID = "uc";
                    
                    maindiv.Controls.Add(control);
                }


            }
            if (hdnDefCus.Value.ToString().Trim() == "C")
            {
                // StudentBL schoolcategory = new StudentBL();
                IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
                int ExtrafieldId = Convert.ToInt32(hdnFieldId.Value);
                if (hdnFieldType.Value.ToString() == "1")
                {
                    TextBox txt = new TextBox();
                    txt.ID = "txt";
                    txt.Width = 150;
                    txt.CssClass = "textbox2";
                    maindiv.Controls.Add(txt);
                    //e.Item.Controls.Add(txt);
                    // string t = txt.ID.ToString();

                }
                if (hdnFieldType.Value.ToString() == "2")
                {
                    CheckBoxList chk = new CheckBoxList();
                    chk.ID = "chk";
                    chk.RepeatDirection = RepeatDirection.Horizontal;


                    //schoolcategory.populatedynamicrchk(ref chk);
                    StuListCont.populatedynamicrchkStuedntBusiness(ref chk, ExtrafieldId);

                    maindiv.Controls.Add(chk);
                }

                if (hdnFieldType.Value.ToString() == "4")
                {
                    DropDownList ddl = new DropDownList();
                    ddl.ID = "ddl";
                    ddl.Width = 155;
                    ddl.CssClass = "textbox_date";



                    // schoolcategory.populatedynamicddl(ref ddl);
                    StuListCont.populatedynamicddlstudentbusiness(ref ddl, ExtrafieldId);

                    maindiv.Controls.Add(ddl);


                }
                if (hdnFieldType.Value.ToString() == "5")
                {
                    Label lbl = new Label();
                    lbl.ID = "lbl";
                    // StudentBL stbl2 = new StudentBL();
                    maindiv.Controls.Add(lbl);
                }
                if (hdnFieldType.Value.ToString() == "3")
                {
                    RadioButtonList rdb = new RadioButtonList();
                    rdb.ID = "rdb";
                    rdb.RepeatDirection = RepeatDirection.Horizontal;
                    // StudentBL stbl2 = new StudentBL();



                    //   schoolcategory.populatedynamicrbtn(ref rdb);
                    StuListCont.populatedynamicrbtnstudentbusiness(ref rdb, ExtrafieldId);
                    maindiv.Controls.Add(rdb);

                }

//*************************01/05/2010**************
                if (hdnFieldType.Value.ToString() == "6")
                {
                    var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");

                    control.ID = "uc";

                    maindiv.Controls.Add(control);
                }


            }


        }
        catch { }



    }

    protected void gvEnrInfo_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        SISInstall SISinstall = new SISInstall();
        //SchoolBL schoolAdd = new SchoolBL();
        // InstallationBL InstallBL = new InstallationBL();
        OpenSISWCFServiceInstallationClient InstallBL = new OpenSISWCFServiceInstallationClient();
        DataTable dtDateFormat = InstallBL.getdateformat();
        if (dtDateFormat.Rows.Count > 0)
        {
            SISinstall.CalenderDateFormat = dtDateFormat.Rows[0][0].ToString();
        }
        // StaffBL STABL = new StaffBL();
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lblAttStrtDate = (Label)e.Row.FindControl("lblAttStrtDate");
            Label lblExitDate = (Label)e.Row.FindControl("lblExitDate");

            if (lblAttStrtDate.Text != "")
            {

                DateTime certdate = DateTime.Parse(lblAttStrtDate.Text);
                lblAttStrtDate.Text = certdate.Date.ToString(SISinstall.CalenderDateFormat);
            }
            if (lblExitDate.Text != "")
            {
                DateTime CertExpDate = DateTime.Parse(lblExitDate.Text);
                lblExitDate.Text = CertExpDate.Date.ToString(SISinstall.CalenderDateFormat);
            }




        }
    }

    protected void rptMedicalInfo_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        try
        {
            // ViewFormLayoutBL vmlBL = new ViewFormLayoutBL();
            HiddenField hdnFieldType = (HiddenField)e.Item.FindControl("hdnFieldType");
            HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
            HtmlControl maindiv = (HtmlControl)e.Item.FindControl("maindiv");
            HiddenField hdnDefCus = (HiddenField)e.Item.FindControl("hdnDefCus");
            if (hdnDefCus.Value.ToString().Trim() == "D")
            {
                if (hdnFieldType.Value.ToString() == "1")
                {
                    TextBox txt = new TextBox();
                    txt.ID = "txt";
                    txt.Width = 150;
                    maindiv.Controls.Add(txt);
                    //e.Item.Controls.Add(txt);
                    // string t = txt.ID.ToString();

                }
                if (hdnFieldType.Value.ToString() == "2")
                {
                    CheckBoxList chk = new CheckBoxList();
                    chk.ID = "chk";
                    chk.RepeatDirection = RepeatDirection.Horizontal;
                    maindiv.Controls.Add(chk);
                }
                if (hdnFieldType.Value.ToString() == "3")
                {
                    //RadioButtonList rdb = new RadioButtonList();
                    //rdb.ID = "rdb";
                    //vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
                    //if (Convert.ToInt32(hdnFieldId.Value) == 10)
                    //{
                    //    vmlBL.PopulateGender(ref rdb);
                    //}
                    //rdb.RepeatDirection = RepeatDirection.Horizontal;
                    //maindiv.Controls.Add(rdb);
                }
                if (hdnFieldType.Value.ToString() == "4")
                {
                    DropDownList ddl = new DropDownList();
                    ddl.ID = "ddl";
                    ddl.Width = 155;
                    ddl.CssClass = "textbox_date";
                    //vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
                    //if (Convert.ToInt32(hdnFieldId.Value) == 11)//ETHNICITY
                    //{
                    //    vmlBL.populateEthnicity(ref ddl);
                    //}
                    //if (Convert.ToInt32(hdnFieldId.Value) == 15 || Convert.ToInt32(hdnFieldId.Value) == 16)//LANGUAGE
                    //{
                    //    vmlBL.populateLanguage(ref ddl);
                    //}
                    //if (Convert.ToInt32(hdnFieldId.Value) == 18)//COUNTRY
                    //{
                    //    vmlBL.populateCountry(ref ddl);
                    //}
                    //if (Convert.ToInt32(hdnFieldId.Value) == 120)//START CONDITION
                    //{
                    //    // vmlBL.populateCountry(ref ddl);
                    //    vmlBL.PopulateEnrollCdn(ref ddl);
                    //}
                    // maindiv.Controls.Add(ddl);
                }
                if (hdnFieldType.Value.ToString() == "5")
                {
                    Label lbl = new Label();
                    lbl.ID = "lbl";
                    // StudentBL stbl2 = new StudentBL();
                    maindiv.Controls.Add(lbl);
                }


            }
            //else if (hdnDefCus.Value.ToString().Trim() == "C")
            //{
            //    if (hdnFieldType.Value.ToString() == "1")
            //    {
            //        TextBox txt = new TextBox();
            //        txt.ID = "txt";
            //        txt.Width = 100;

            //        maindiv.Controls.Add(txt);

            //    }
            //    if (hdnFieldType.Value.ToString() == "2")
            //    {
            //        CheckBoxList chk = new CheckBoxList();
            //        chk.ID = "chk";
            //        vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
            //        vmlBL.populatedynamicrchk(ref chk);
            //        chk.RepeatDirection = RepeatDirection.Horizontal;
            //        maindiv.Controls.Add(chk);
            //    }
            //    if (hdnFieldType.Value.ToString() == "3")
            //    {
            //        RadioButtonList rdb = new RadioButtonList();
            //        rdb.ID = "rdb";
            //        vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
            //        vmlBL.populatedynamicrbtn(ref rdb);
            //        rdb.RepeatDirection = RepeatDirection.Horizontal;

            //        maindiv.Controls.Add(rdb);
            //    }
            //    if (hdnFieldType.Value.ToString() == "4")
            //    {
            //        DropDownList ddl = new DropDownList();
            //        ddl.ID = "ddl";
            //        vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
            //        vmlBL.populatedynamicddl(ref ddl);
            //        ddl.AutoPostBack = false;
            //        maindiv.Controls.Add(ddl);

            //    }
            //    if (hdnFieldType.Value.ToString() == "5")
            //    {
            //        Label lbl = new Label();
            //        lbl.ID = "lbl";
            //        StudentBL stbl2 = new StudentBL();

            //        maindiv.Controls.Add(lbl);
            //    }
            //}

            //if (hdnDefCus.Value.ToString().Trim() == "D")
            //{
            //    if (Convert.ToInt32(hdnFieldId.Value) == 1 || Convert.ToInt32(hdnFieldId.Value) == 13 || Convert.ToInt32(hdnFieldId.Value) == 14 || Convert.ToInt32(hdnFieldId.Value) == 110 || Convert.ToInt32(hdnFieldId.Value) == 11 || Convert.ToInt32(hdnFieldId.Value) == 15)
            //    {
            //        e.Item.Visible = false;
            //    }
            //}
            // fieldid++;

        }
        catch { }


    }

    protected void rptrSpecEdu_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        // StudentBL schoolcategory = new StudentBL();
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        try
        {
            // ViewFormLayoutBL vmlBL = new ViewFormLayoutBL();


            // EntryFormLayoutBL categoryfields = new EntryFormLayoutBL();
            OpenSISWCFServiceStudentFormLayoutClient categoryfields = new OpenSISWCFServiceStudentFormLayoutClient();
            hdnInitialCatId.Value = hdnCatId.Value;
            int CatId = Convert.ToInt32(hdnCatId.Value);
            // ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);
            HiddenField hdnFieldType = (HiddenField)e.Item.FindControl("hdnFieldType");
            HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
            HtmlControl maindiv = (HtmlControl)e.Item.FindControl("maindiv");
            HiddenField hdnDefCus = (HiddenField)e.Item.FindControl("hdnDefCus");
            Label lblfldnam = (Label)e.Item.FindControl("lblfldnam");

            DataTable dtspec = schoolcategory.PopulateSpecialFieldStudentBusiness(SchoolID, Session["MLUICulture"].ToString());
            for (int i = 0; i < dtspec.Rows.Count; i++)
            {
                if (hdnFieldId.Value.ToString() == dtspec.Rows[i]["FieldId"].ToString())
                {
                    lblfldnam.Text = dtspec.Rows[i]["FieldName"].ToString();
                }
            }

        }
        catch { }

    }

    protected void rptrGiftProg_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        // StudentBL schoolcategory = new StudentBL();
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        try
        {
            // ViewFormLayoutBL vmlBL = new ViewFormLayoutBL();


            // EntryFormLayoutBL categoryfields = new EntryFormLayoutBL();
            OpenSISWCFServiceStudentFormLayoutClient categoryfields = new OpenSISWCFServiceStudentFormLayoutClient();
            string Value = hdnCatId.Value;
            int CatId = Convert.ToInt32(hdnCatId.Value);
            //  ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);
            HiddenField hdnFieldType = (HiddenField)e.Item.FindControl("hdnFieldType");
            HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
            HtmlControl maindiv = (HtmlControl)e.Item.FindControl("maindiv");
            HiddenField hdnDefCus = (HiddenField)e.Item.FindControl("hdnDefCus");
            Label lblfldnam = (Label)e.Item.FindControl("lblfldnam");

            DataTable dtspec = schoolcategory.PopulateGiftFieldStudentBusiness(SchoolID, Session["MLUICulture"].ToString());
            for (int i = 0; i < dtspec.Rows.Count; i++)
            {
                if (hdnFieldId.Value.ToString() == dtspec.Rows[i]["FieldId"].ToString())
                {
                    lblfldnam.Text = dtspec.Rows[i]["FieldName"].ToString();
                }
            }

        }
        catch { }
    }

    protected void rptrSpecial_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        // StudentBL schoolcategory = new StudentBL();
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        try
        {
            // ViewFormLayoutBL vmlBL = new ViewFormLayoutBL();


            // EntryFormLayoutBL categoryfields = new EntryFormLayoutBL();
            OpenSISWCFServiceStudentFormLayoutClient categoryfields = new OpenSISWCFServiceStudentFormLayoutClient();
            hdnInitialCatId.Value = hdnCatId.Value;
            int CatId = Convert.ToInt32(hdnCatId.Value);
            //  ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);

            //  HiddenField hdnfldnametest = (HiddenField)e.Item.FindControl("hdnfldnametest");
            HiddenField hdnFieldType = (HiddenField)e.Item.FindControl("hdnFieldType");
            HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
            HtmlControl maindiv = (HtmlControl)e.Item.FindControl("maindiv");
            HiddenField hdnDefCus = (HiddenField)e.Item.FindControl("hdnDefCus");

            // string test = hdnfldnametest.Value.ToString();

            if (hdnFieldType.Value.ToString() == "1")
            {
                TextBox txt = new TextBox();
                txt.ID = "txt";
                txt.Width = 150;
                maindiv.Controls.Add(txt);

            }
            if (hdnFieldType.Value.ToString() == "2")
            {
                CheckBoxList chk = new CheckBoxList();
                chk.ID = "chk";
                chk.RepeatDirection = RepeatDirection.Horizontal;
                maindiv.Controls.Add(chk);
            }

            if (hdnFieldType.Value.ToString() == "3")
            {
                RadioButtonList rdb = new RadioButtonList();
                rdb.ID = "rdb";

                //if (hdnFieldId.Value.ToString() == "1")
                //{
                    //  schoolcategory.PopulateYesNo(ref rdb);
                    StuListCont.PopulateYesNo(ref rdb);
                //}

                rdb.RepeatDirection = RepeatDirection.Horizontal;

                maindiv.Controls.Add(rdb);
            }


            if (hdnFieldType.Value.ToString() == "4")
            {
                //DropDownList ddl = new DropDownList();
                //ddl.ID = "ddl";

                // ddl.CssClass = "textbox_date";

                DropDownList ddl = new DropDownList();
                ddl.ID = "ddl";
                ddl.Width = 155;
                ddl.CssClass = "dropdown2";

                if (hdnFieldId.Value.ToString() == "2")
                {
                    // schoolcategory.PopulateEvaluationType(ref ddl);
                    StuListCont.PopulateEvaluationType(ref ddl);
                }
                if (hdnFieldId.Value.ToString() == "4")
                {
                    StuListCont.PopulateSpecialEduStatus(ref ddl);
                }
                if (hdnFieldId.Value.ToString() == "5")
                {
                    StuListCont.PopulateDisabilities(ref ddl);
                }
                if (hdnFieldId.Value.ToString() == "6")
                {
                    StuListCont.PopulateDisabilities(ref ddl);
                }
                if (hdnFieldId.Value.ToString() == "9")
                {
                    StuListCont.PopulateSpecialEduExistStatus(ref ddl);
                }

                maindiv.Controls.Add(ddl);
            }
            if (hdnFieldType.Value.ToString() == "5")
            {
                Label lbl = new Label();
                lbl.ID = "lbl";
                //StudentBL stbl2 = new StudentBL();
                maindiv.Controls.Add(lbl);
            }

            if (hdnFieldType.Value.ToString() == "6")
            {
                var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");

                control.ID = "uc";
                //StudentBL stbl2 = new StudentBL();
                maindiv.Controls.Add(control);
            }



        }
        catch { }


    }

    protected void rptrGiftforadd_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        // StudentBL schoolcategory = new StudentBL();
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        try
        {
            // ViewFormLayoutBL vmlBL = new ViewFormLayoutBL();


            //  EntryFormLayoutBL categoryfields = new EntryFormLayoutBL();
            OpenSISWCFServiceStudentFormLayoutClient categoryfields = new OpenSISWCFServiceStudentFormLayoutClient();
            hdnInitialCatId.Value = hdnCatId.Value;
            int CatId = Convert.ToInt32(hdnCatId.Value);
            //  ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);
            HiddenField hdnFieldType = (HiddenField)e.Item.FindControl("hdnFieldType");
            HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
            HtmlControl maindiv = (HtmlControl)e.Item.FindControl("maindiv");
            HiddenField hdnDefCus = (HiddenField)e.Item.FindControl("hdnDefCus");

            if (hdnFieldType.Value.ToString() == "1")
            {
                TextBox txt = new TextBox();
                txt.ID = "txt";
                txt.Width = 150;
                maindiv.Controls.Add(txt);

            }
            if (hdnFieldType.Value.ToString() == "2")
            {
                CheckBoxList chk = new CheckBoxList();
                chk.ID = "chk";
                chk.RepeatDirection = RepeatDirection.Horizontal;
                maindiv.Controls.Add(chk);
            }


            if (hdnFieldType.Value.ToString() == "5")
            {
                Label lbl = new Label();
                lbl.ID = "lbl";
                // StudentBL stbl2 = new StudentBL();
                maindiv.Controls.Add(lbl);
            }

            if (hdnFieldType.Value.ToString() == "3")
            {
                RadioButtonList rdb = new RadioButtonList();
                rdb.ID = "rdb";

                if (hdnFieldId.Value.ToString() == "1")
                {
                    //  schoolcategory.PopulateYesNo(ref rdb);
                    StuListCont.PopulateYesNo(ref rdb);
                }

                rdb.RepeatDirection = RepeatDirection.Horizontal;

                maindiv.Controls.Add(rdb);
            }
            if (hdnFieldType.Value.ToString() == "4")
            {
                DropDownList ddl = new DropDownList();
                ddl.ID = "ddl";
                ddl.CssClass = "dropdown2";
                if (hdnFieldId.Value.ToString() == "2")
                {
                    //schoolcategory.PopulateGiftedCategory(ref ddl);
                    StuListCont.PopulateGiftedCategory(ref ddl);
                }

                maindiv.Controls.Add(ddl);
            }

            if (hdnFieldType.Value.ToString() == "6")
            {
                var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");

                control.ID = "uc";



                maindiv.Controls.Add(control);
            }


        }
        catch { }


    }

    protected void rptrVaceField_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        try
        {
            // ViewFormLayoutBL vmlBL = new ViewFormLayoutBL();
            HiddenField hdnFieldType = (HiddenField)e.Item.FindControl("hdnFieldType");
            HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
            HtmlControl maindiv = (HtmlControl)e.Item.FindControl("maindiv");
            HiddenField hdnDefCus = (HiddenField)e.Item.FindControl("hdnDefCus");
            if (hdnDefCus.Value.ToString().Trim() == "D")
            {
                if (hdnFieldType.Value.ToString() == "1")
                {
                    TextBox txt = new TextBox();
                    txt.ID = "txt";
                    txt.Width = 150;
                    maindiv.Controls.Add(txt);
                    //e.Item.Controls.Add(txt);
                    // string t = txt.ID.ToString();

                }
                if (hdnFieldType.Value.ToString() == "2")
                {
                    CheckBoxList chk = new CheckBoxList();
                    chk.ID = "chk";
                    chk.RepeatDirection = RepeatDirection.Horizontal;
                    maindiv.Controls.Add(chk);
                }
                if (hdnFieldType.Value.ToString() == "3")
                {
                    //RadioButtonList rdb = new RadioButtonList();
                    //rdb.ID = "rdb";
                    //vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
                    //if (Convert.ToInt32(hdnFieldId.Value) == 10)
                    //{
                    //    vmlBL.PopulateGender(ref rdb);
                    //}
                    //rdb.RepeatDirection = RepeatDirection.Horizontal;
                    //maindiv.Controls.Add(rdb);
                }
                if (hdnFieldType.Value.ToString() == "4")
                {
                    DropDownList ddl = new DropDownList();
                    ddl.ID = "ddl";
                    ddl.Width = 155;
                    ddl.CssClass = "textbox_date";
                    //vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
                    //if (Convert.ToInt32(hdnFieldId.Value) == 11)//ETHNICITY
                    //{
                    //    vmlBL.populateEthnicity(ref ddl);
                    //}
                    //if (Convert.ToInt32(hdnFieldId.Value) == 15 || Convert.ToInt32(hdnFieldId.Value) == 16)//LANGUAGE
                    //{
                    //    vmlBL.populateLanguage(ref ddl);
                    //}
                    //if (Convert.ToInt32(hdnFieldId.Value) == 18)//COUNTRY
                    //{
                    //    vmlBL.populateCountry(ref ddl);
                    //}
                    //if (Convert.ToInt32(hdnFieldId.Value) == 120)//START CONDITION
                    //{
                    //    // vmlBL.populateCountry(ref ddl);
                    //    vmlBL.PopulateEnrollCdn(ref ddl);
                    //}
                    // maindiv.Controls.Add(ddl);
                }
                if (hdnFieldType.Value.ToString() == "5")
                {
                    Label lbl = new Label();
                    lbl.ID = "lbl";
                    //StudentBL stbl2 = new StudentBL();
                    maindiv.Controls.Add(lbl);
                }

                //****************29/04/2010*******************

                if (hdnFieldType.Value.ToString() == "6")
                {
                    var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                    control.ID = "uc";
                    maindiv.Controls.Add(control);
                }
            }
            //else if (hdnDefCus.Value.ToString().Trim() == "C")
            //{
            //    if (hdnFieldType.Value.ToString() == "1")
            //    {
            //        TextBox txt = new TextBox();
            //        txt.ID = "txt";
            //        txt.Width = 100;

            //        maindiv.Controls.Add(txt);

            //    }
            //    if (hdnFieldType.Value.ToString() == "2")
            //    {
            //        CheckBoxList chk = new CheckBoxList();
            //        chk.ID = "chk";
            //        vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
            //        vmlBL.populatedynamicrchk(ref chk);
            //        chk.RepeatDirection = RepeatDirection.Horizontal;
            //        maindiv.Controls.Add(chk);
            //    }
            //    if (hdnFieldType.Value.ToString() == "3")
            //    {
            //        RadioButtonList rdb = new RadioButtonList();
            //        rdb.ID = "rdb";
            //        vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
            //        vmlBL.populatedynamicrbtn(ref rdb);
            //        rdb.RepeatDirection = RepeatDirection.Horizontal;

            //        maindiv.Controls.Add(rdb);
            //    }
            //    if (hdnFieldType.Value.ToString() == "4")
            //    {
            //        DropDownList ddl = new DropDownList();
            //        ddl.ID = "ddl";
            //        vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
            //        vmlBL.populatedynamicddl(ref ddl);
            //        ddl.AutoPostBack = false;
            //        maindiv.Controls.Add(ddl);

            //    }
            //    if (hdnFieldType.Value.ToString() == "5")
            //    {
            //        Label lbl = new Label();
            //        lbl.ID = "lbl";
            //        StudentBL stbl2 = new StudentBL();

            //        maindiv.Controls.Add(lbl);
            //    }
            //}

            //if (hdnDefCus.Value.ToString().Trim() == "D")
            //{
            //    if (Convert.ToInt32(hdnFieldId.Value) == 1 || Convert.ToInt32(hdnFieldId.Value) == 13 || Convert.ToInt32(hdnFieldId.Value) == 14 || Convert.ToInt32(hdnFieldId.Value) == 110 || Convert.ToInt32(hdnFieldId.Value) == 11 || Convert.ToInt32(hdnFieldId.Value) == 15)
            //    {
            //        e.Item.Visible = false;
            //    }
            //}
            // fieldid++;

        }
        catch { }


    }

    protected void btnSaveEnrInfo_Click(object sender, EventArgs e)
    {
        btnPrev.Visible = true;
        ibtnEnrInfo.Visible = true;

        //StudentBL schoolcategory = new StudentBL();
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        DataTable SessiondtEnrol = (DataTable)Session["Enroltable"];
        if (SessiondtEnrol != null)
        {
            DataRow dr = SessiondtEnrol.NewRow();
            dr["AttStrtDate"] = txtAttStrtDate.Text.ToString();
            dr["ExitDate"] = txtExitdate.Text.ToString();
            dr["ExitCode"] = ddlExitCode.SelectedItem.Text;
            dr["Exitreason"] = txtExitreason.Text.ToString();
            dr["StartCondition"] = txtStartCond.Text.ToString();
            dr["ExitCodeValue"] = ddlExitCode.SelectedItem.Value;


            SessiondtEnrol.Rows.Add(dr);

            Session.Add("Enroltable", SessiondtEnrol);

            gvEnrInfo.DataSource = SessiondtEnrol;
            gvEnrInfo.DataBind();
        }
        else
        {
            DataTable dtEnrol = new DataTable();
            dtEnrol.Columns.Add("AttStrtDate");
            dtEnrol.Columns.Add("ExitDate");
            dtEnrol.Columns.Add("ExitCode");
            dtEnrol.Columns.Add("Exitreason");
            dtEnrol.Columns.Add("StartCondition");
            //added
            dtEnrol.Columns.Add("ExitCodeValue");

            DataRow dr = dtEnrol.NewRow();
            dr["AttStrtDate"] = txtAttStrtDate.Text.ToString();
            dr["ExitDate"] = txtExitdate.Text.ToString();
            dr["ExitCode"] = ddlExitCode.SelectedItem.Text;
            dr["Exitreason"] = txtExitreason.Text.ToString();
            dr["StartCondition"] = txtStartCond.Text.ToString();
            dr["ExitCodeValue"] = ddlExitCode.SelectedItem.Value;


            dtEnrol.Rows.Add(dr);

            Session.Add("Enroltable", dtEnrol);

            gvEnrInfo.DataSource = dtEnrol;
            gvEnrInfo.DataBind();
        }


        //  PopulateVccinationGridview();



        PopulateSchoolInfoFieldData();
        // PopulateVaccinationFieldData();



    }

    protected void imgbtnAddSpecial_Click(object sender, ImageClickEventArgs e)
    {
        //=== PopulateSpecialFields();

        mdlAddSpec.Enabled = true;
        mdlAddSpec.Show();
        int Treepos = Convert.ToInt32(TreeView1.SelectedNode.Value.Split(",".ToCharArray())[1]);
        if ((Treepos + 1) == Convert.ToInt32(TreeView1.Nodes.Count))
        {
            btnSave.Visible = true;
            btnPrev.Visible = true;
            btnNext.Visible = false;
        }
        PopulateGiftValue();
        PopulateSpecialValue();
    }

    protected void imgbtnAddGifted_Click(object sender, ImageClickEventArgs e)
    {
        //== PopulateGiftedFields();
        mdlGiftProg.Enabled = true;
        mdlGiftProg.Show();
        int Treepos = Convert.ToInt32(TreeView1.SelectedNode.Value.Split(",".ToCharArray())[1]);
        if ((Treepos + 1) == Convert.ToInt32(TreeView1.Nodes.Count))
        {
            btnSave.Visible = true;
            btnPrev.Visible = true;
            btnNext.Visible = false;
        }
        PopulateGiftValue();
        PopulateSpecialValue();
    }

    protected void btnSaveSpec_Click(object sender, EventArgs e)
    {
        // StudentBL schoolcategory = new StudentBL();
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        //  ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
        int SchoolID = Convert.ToInt32(Session["SchoolID"]);

        //schoolcategory.SchoolID = 
        DataTable SessiondtSpecialEdu = (DataTable)Session["SpecialEduForInsert"];
        if (SessiondtSpecialEdu == null)
        {
            DataTable dtUserData = new DataTable();
            dtUserData.Columns.Add("Value");
            dtUserData.Columns.Add("FieldId");
            dtUserData.Columns.Add("FieldCatagory");
            dtUserData.Columns.Add("FieldName");
            dtUserData.Columns.Add("Category");

            foreach (var C in pnlAddSpec.Controls)
            {

                if (object.ReferenceEquals(C.GetType(), typeof(Repeater)))
                {

                    for (int i = 0; i <= rptrSpecial.Items.Count - 1; i++)
                    {
                        DataRow dr = dtUserData.NewRow();
                        TextBox txtfieldvalue = (TextBox)rptrSpecial.Items[i].FindControl("txt");
                        DropDownList ddlfieldvalue = (DropDownList)rptrSpecial.Items[i].FindControl("ddl");
                        RadioButtonList rdbfieldvalue = (RadioButtonList)rptrSpecial.Items[i].FindControl("rdb");
                        //TextBox txtfieldvalue = (TextBox)rptrSpecial.Items[i].FindControl("txt");
                        HiddenField hdnFieldId = (HiddenField)rptrSpecial.Items[i].FindControl("hdnFieldId");
                        if (txtfieldvalue != null)
                        {
                            dr[0] = txtfieldvalue.Text.ToString();
                            dr[1] = hdnFieldId.Value.ToString();
                        }

                        //*********************01/05/2010**************
                        DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrSpecial.Items[i].FindControl("uc");
                        if (uc != null)
                        {

                            dr[0] = uc.Value.ToString();
                            dr[1] = hdnFieldId.Value.ToString();
                        }


                        if (ddlfieldvalue != null)
                        {


                            if (ddlfieldvalue.SelectedIndex != -1)
                            {
                                dr[0] = ddlfieldvalue.SelectedItem.Value.ToString();
                                dr[1] = hdnFieldId.Value.ToString();
                            }

                        }

                        if (rdbfieldvalue != null)
                        {
                            for (int r = 0; r < rdbfieldvalue.Items.Count; r++)
                            {
                                if (rdbfieldvalue.Items[r].Selected)
                                {
                                    dr[0] = rdbfieldvalue.SelectedItem.Value.ToString();
                                    //dr[1] = hdnFieldId.Value.ToString();
                                    //dr[2] = hdnCatId.Value.ToString();
                                    //dr[3] = hdnDefCus.Value.ToString();
                                    //dtUserData.Rows.Add(dr);
                                    dr[1] = hdnFieldId.Value.ToString();
                                }

                            }

                        }
                        dr[4] = hdnCatId.Value.ToString();
                        dtUserData.Rows.Add(dr);
                    }
                }
            }






            string SessionTableName = "SpecialEduForInsert";
            Session.Add(SessionTableName, dtUserData);



            rptrSpecEdu.DataSource = dtUserData;
            rptrSpecEdu.DataBind();
        }
        else
        {
            foreach (var C in pnlAddSpec.Controls)
            {

                if (object.ReferenceEquals(C.GetType(), typeof(Repeater)))
                {

                    for (int i = 0; i <= rptrSpecial.Items.Count - 1; i++)
                    {
                        DataRow dr = SessiondtSpecialEdu.NewRow();
                        TextBox txtfieldvalue = (TextBox)rptrSpecial.Items[i].FindControl("txt");
                        DropDownList ddlfieldvalue = (DropDownList)rptrSpecial.Items[i].FindControl("ddl");
                        RadioButtonList rdbfieldvalue = (RadioButtonList)rptrSpecial.Items[i].FindControl("rdb");
                        //TextBox txtfieldvalue = (TextBox)rptrSpecial.Items[i].FindControl("txt");
                        HiddenField hdnFieldId = (HiddenField)rptrSpecial.Items[i].FindControl("hdnFieldId");
                        if (txtfieldvalue != null)
                        {
                            dr[0] = txtfieldvalue.Text.ToString();
                            dr[1] = hdnFieldId.Value.ToString();
                        }

                        //*********************01/05/2010**************
                        DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrSpecial.Items[i].FindControl("uc");
                        if (uc != null)
                        {

                            dr[0] = uc.Value.ToString();
                            dr[1] = hdnFieldId.Value.ToString();
                        }


                        if (ddlfieldvalue != null)
                        {


                            if (ddlfieldvalue.SelectedIndex != -1)
                            {
                                dr[0] = ddlfieldvalue.SelectedItem.Value.ToString();
                                dr[1] = hdnFieldId.Value.ToString();
                            }

                        }

                        if (rdbfieldvalue != null)
                        {
                            for (int r = 0; r < rdbfieldvalue.Items.Count; r++)
                            {
                                if (rdbfieldvalue.Items[r].Selected)
                                {
                                    dr[0] = rdbfieldvalue.SelectedItem.Value.ToString();
                                    //dr[1] = hdnFieldId.Value.ToString();
                                    //dr[2] = hdnCatId.Value.ToString();
                                    //dr[3] = hdnDefCus.Value.ToString();
                                    //dtUserData.Rows.Add(dr);
                                    dr[1] = hdnFieldId.Value.ToString();
                                }

                            }

                        }
                        dr[4] = hdnCatId.Value.ToString();
                        SessiondtSpecialEdu.Rows.Add(dr);
                    }
                }
            }




            Session.Add("SpecialEduForInsert", SessiondtSpecialEdu);
            rptrSpecEdu.DataSource = SessiondtSpecialEdu;
            rptrSpecEdu.DataBind();
        }



    }

    protected void btnSaveGift_Click(object sender, EventArgs e)
    {
        // StudentBL schoolcategory = new StudentBL();
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        DataTable SessiondtGift = (DataTable)Session["SpecialGiftForInsert"];
        if (SessiondtGift == null)
        {
            DataTable dtUserData = new DataTable();
            dtUserData.Columns.Add("Value");
            dtUserData.Columns.Add("FieldId");
            dtUserData.Columns.Add("FieldCatagory");
            dtUserData.Columns.Add("FieldName");
            dtUserData.Columns.Add("Category");

            foreach (var C in pnlAddGiftProg.Controls)
            {

                if (object.ReferenceEquals(C.GetType(), typeof(Repeater)))
                {

                    for (int i = 0; i <= rptrGiftforadd.Items.Count - 1; i++)
                    {
                        DataRow dr = dtUserData.NewRow();
                        TextBox txtfieldvalue = (TextBox)rptrGiftforadd.Items[i].FindControl("txt");
                        DropDownList ddlfieldvalue = (DropDownList)rptrGiftforadd.Items[i].FindControl("ddl");
                        RadioButtonList rdbfieldvalue = (RadioButtonList)rptrGiftforadd.Items[i].FindControl("rdb");
                        //TextBox txtfieldvalue = (TextBox)rptrSpecial.Items[i].FindControl("txt");
                        HiddenField hdnFieldId = (HiddenField)rptrGiftforadd.Items[i].FindControl("hdnFieldId");
                        if (txtfieldvalue != null)
                        {
                            dr[0] = txtfieldvalue.Text.ToString();
                            dr[1] = hdnFieldId.Value.ToString();
                        }
                        //*********************01/05/2010**************
                        DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrGiftforadd.Items[i].FindControl("uc");
                        if (uc != null)
                        {

                            dr[0] = uc.Value.ToString();
                            dr[1] = hdnFieldId.Value.ToString();
                        }


                        if (ddlfieldvalue != null)
                        {


                            if (ddlfieldvalue.SelectedIndex != -1)
                            {
                                dr[0] = ddlfieldvalue.SelectedItem.Value.ToString();
                                dr[1] = hdnFieldId.Value.ToString();
                            }

                        }

                        if (rdbfieldvalue != null)
                        {
                            for (int r = 0; r < rdbfieldvalue.Items.Count; r++)
                            {
                                if (rdbfieldvalue.Items[r].Selected)
                                {
                                    dr[0] = rdbfieldvalue.SelectedItem.Value.ToString();

                                    dr[1] = hdnFieldId.Value.ToString();
                                }

                            }

                        }
                        dr[4] = hdnCatId.Value.ToString();

                        dtUserData.Rows.Add(dr);
                    }
                }
            }







            string SessionTableName = "SpecialGiftForInsert";
            Session.Add(SessionTableName, dtUserData);

            rptrGiftProg.DataSource = dtUserData;
            rptrGiftProg.DataBind();
        }
        else
        {

            foreach (var C in pnlAddGiftProg.Controls)
            {

                if (object.ReferenceEquals(C.GetType(), typeof(Repeater)))
                {

                    for (int i = 0; i <= rptrGiftforadd.Items.Count - 1; i++)
                    {
                        DataRow dr = SessiondtGift.NewRow();
                        TextBox txtfieldvalue = (TextBox)rptrGiftforadd.Items[i].FindControl("txt");
                        DropDownList ddlfieldvalue = (DropDownList)rptrGiftforadd.Items[i].FindControl("ddl");
                        RadioButtonList rdbfieldvalue = (RadioButtonList)rptrGiftforadd.Items[i].FindControl("rdb");
                        //TextBox txtfieldvalue = (TextBox)rptrSpecial.Items[i].FindControl("txt");
                        HiddenField hdnFieldId = (HiddenField)rptrGiftforadd.Items[i].FindControl("hdnFieldId");
                        if (txtfieldvalue != null)
                        {
                            dr[0] = txtfieldvalue.Text.ToString();
                            dr[1] = hdnFieldId.Value.ToString();
                        }

                        //*********************01/05/2010**************
                        DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrGiftforadd.Items[i].FindControl("uc");
                        if (uc != null)
                        {

                            dr[0] = uc.Value.ToString();
                            dr[1] = hdnFieldId.Value.ToString();
                        }

                        if (ddlfieldvalue != null)
                        {


                            if (ddlfieldvalue.SelectedIndex != -1)
                            {
                                dr[0] = ddlfieldvalue.SelectedItem.Value.ToString();
                                dr[1] = hdnFieldId.Value.ToString();
                            }

                        }

                        if (rdbfieldvalue != null)
                        {
                            for (int r = 0; r < rdbfieldvalue.Items.Count; r++)
                            {
                                if (rdbfieldvalue.Items[r].Selected)
                                {
                                    dr[0] = rdbfieldvalue.SelectedItem.Value.ToString();
                                    //dr[1] = hdnFieldId.Value.ToString();
                                    //dr[2] = hdnCatId.Value.ToString();
                                    //dr[3] = hdnDefCus.Value.ToString();
                                    //dtUserData.Rows.Add(dr);
                                    dr[1] = hdnFieldId.Value.ToString();
                                }

                            }

                        }

                        dr[4] = hdnCatId.Value.ToString();

                        SessiondtGift.Rows.Add(dr);
                    }
                }
            }


            Session.Add("SpecialGiftForInsert", SessiondtGift);
            rptrGiftProg.DataSource = SessiondtGift;
            rptrGiftProg.DataBind();
        }



    }

    protected void rptrVccination_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        try
        {
            // ViewFormLayoutBL vmlBL = new ViewFormLayoutBL();


            // EntryFormLayoutBL categoryfields = new EntryFormLayoutBL();
            OpenSISWCFServiceStudentFormLayoutClient categoryfields = new OpenSISWCFServiceStudentFormLayoutClient();
            string Value = hdnCatId.Value;
            int CatId = Convert.ToInt32(hdnCatId.Value);
            //  ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);
            HiddenField hdnFieldType = (HiddenField)e.Item.FindControl("hdnFieldType");
            HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
            HtmlControl maindiv = (HtmlControl)e.Item.FindControl("maindivgift");
            HiddenField hdnDefCus = (HiddenField)e.Item.FindControl("hdnDefCus");
            HiddenField hdnFieldValue = (HiddenField)e.Item.FindControl("hdnFieldValue");
            Label lblfldnam = (Label)e.Item.FindControl("lblfldnam");

            //multilangual*********

            //DataTable dtspec = schoolcategory.PopulateGiftFieldStudentBusiness(SchoolID, Session["MLUICulture"].ToString());
            DataTable dtspec = schoolcategory.GetVaccinationFieldsStudentBusiness(SchoolID, CatId);
            for (int i = 0; i < dtspec.Rows.Count; i++)
            {
                if (hdnFieldId.Value.ToString() == dtspec.Rows[i]["FieldId"].ToString())
                {
                    lblfldnam.Text = dtspec.Rows[i]["FieldName"].ToString();
                }
            }
            if (hdnFieldType.Value.ToString() == "1")
            {
                TextBox txt = new TextBox();
                txt.ID = "txt";
                txt.Width = 150;
                txt.Text = hdnFieldValue.Value.ToString();
                maindiv.Controls.Add(txt);

            }


            if (hdnFieldType.Value.ToString() == "2")
            {
                CheckBoxList chk = new CheckBoxList();
                chk.ID = "chk";
                chk.RepeatDirection = RepeatDirection.Horizontal;
                maindiv.Controls.Add(chk);
            }


            //if (hdnFieldType.Value.ToString() == "5")
            //{
            //    Label lbl = new Label();
            //    lbl.ID = "lbl";
            //    // StudentBL stbl2 = new StudentBL();
            //    maindiv.Controls.Add(lbl);
            //}

            if (hdnFieldType.Value.ToString() == "3")
            {
                RadioButtonList rdb = new RadioButtonList();
                rdb.ID = "rdb";

                if (hdnFieldId.Value.ToString() == "1")
                {
                    //  schoolcategory.PopulateYesNo(ref rdb);
                    StuListCont.PopulateYesNo(ref rdb);
                }

                rdb.RepeatDirection = RepeatDirection.Horizontal;
                rdb.Items.FindByValue(hdnFieldValue.Value).Selected = true;
                maindiv.Controls.Add(rdb);
            }
            if (hdnFieldType.Value.ToString() == "4")
            {
                DropDownList ddl = new DropDownList();
                ddl.ID = "ddl";
                ddl.CssClass = "dropdown2";
                if (hdnFieldId.Value.ToString() == "2")
                {
                    //schoolcategory.PopulateGiftedCategory(ref ddl);
                    StuListCont.PopulateGiftedCategory(ref ddl);
                }
                ddl.Items.FindByValue(hdnFieldValue.Value).Selected = true;
                maindiv.Controls.Add(ddl);
            }
            //**************01/05/2010*********
            if (hdnFieldType.Value.ToString() == "6")
            {
                var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                control.ID = "uc";

                control.Value = hdnFieldValue.Value.ToString();
                maindiv.Controls.Add(control);

            }




        }
        catch { }
    }

    protected void DataStoreProgramForVaccination()
    {
        DataTable VaccinationForInsert = (DataTable)Session["VaccinationForInsert"];


        for (int i = 0; i <= rptrVccination.Items.Count - 1; i++)
        {
            //DataRow dr = SessiondtGift.NewRow();
            TextBox txtfieldvalue = (TextBox)rptrVccination.Items[i].FindControl("txt");
            DropDownList ddlfieldvalue = (DropDownList)rptrVccination.Items[i].FindControl("ddl");
            RadioButtonList rdbfieldvalue = (RadioButtonList)rptrVccination.Items[i].FindControl("rdb");
            //TextBox txtfieldvalue = (TextBox)rptrSpecial.Items[i].FindControl("txt");
            HiddenField hdnFieldId = (HiddenField)rptrVccination.Items[i].FindControl("hdnFieldId");
            HiddenField hdnFieldType = (HiddenField)rptrVccination.Items[i].FindControl("hdnFieldType");
            DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrVccination.Items[i].FindControl("uc");
            if (txtfieldvalue != null)
            {
                //dr[0] = txtfieldvalue.Text.ToString();
                //dr[1] = hdnFieldId.Value.ToString();
                //dr["Value"] = txtfieldvalue.Text.ToString();
                //dr["FieldId"] = hdnFieldId.Value.ToString();
                //dr["FieldType"] = hdnFieldType.Value.ToString();
                VaccinationForInsert.Rows[i]["Value"] = txtfieldvalue.Text.ToString();
            }
            if (uc != null)
            {

                VaccinationForInsert.Rows[i]["Value"] = uc.Value.ToString();
            }
            if (ddlfieldvalue != null)
            {


                if (ddlfieldvalue.SelectedIndex != -1)
                {

                    VaccinationForInsert.Rows[i]["Value"] = ddlfieldvalue.SelectedItem.Value.ToString();
                }

            }

            if (rdbfieldvalue != null)
            {
                for (int r = 0; r < rdbfieldvalue.Items.Count; r++)
                {
                    if (rdbfieldvalue.Items[r].Selected)
                    {
                        //dr[0] = rdbfieldvalue.SelectedItem.Value.ToString();

                        //dr[1] = hdnFieldId.Value.ToString();
                        //dr["Value"] = rdbfieldvalue.SelectedItem.Value.ToString();
                        //dr["FieldId"] = hdnFieldId.Value.ToString();
                        //dr["FieldType"] = hdnFieldType.Value.ToString(); ;
                        VaccinationForInsert.Rows[i]["Value"] = rdbfieldvalue.SelectedItem.Value.ToString();
                    }

                }

            }

            // dr[4] = hdnCatId.Value.ToString();
            //dr["Cat_Id"] = hdnCatId.Value.ToString();

            // SessiondtGift.Rows.Add(dr);
            VaccinationForInsert.AcceptChanges();
        }



        Session.Add("VaccinationForInsert", VaccinationForInsert);
        rptrVccination.DataSource = VaccinationForInsert;
        rptrVccination.DataBind();
    }

    public void PopulateVccinationValue()
    {


        DataTable SessiondtGift = (DataTable)Session["VaccinationForInsert"];
        if (SessiondtGift != null)
        {
            rptrVccination.DataSource = SessiondtGift;
            rptrVccination.DataBind();

        }
       
    }


    protected void rptAdditionalList_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        // StudentBL schoolcategory = new StudentBL();
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        try
        {
            // ViewFormLayoutBL vmlBL = new ViewFormLayoutBL();


            // EntryFormLayoutBL categoryfields = new EntryFormLayoutBL();
            OpenSISWCFServiceStudentFormLayoutClient categoryfields = new OpenSISWCFServiceStudentFormLayoutClient();
            hdnInitialCatId.Value = hdnCatId.Value;
            int CatId = Convert.ToInt32(hdnCatId.Value);
            //  ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);

            //  HiddenField hdnfldnametest = (HiddenField)e.Item.FindControl("hdnfldnametest");
            HiddenField hdnFieldType = (HiddenField)e.Item.FindControl("hdnFieldType");
            HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
            HtmlControl maindiv = (HtmlControl)e.Item.FindControl("maindiv");
            HiddenField hdnDefCus = (HiddenField)e.Item.FindControl("hdnDefCus");

            // string test = hdnfldnametest.Value.ToString();

            if (hdnFieldType.Value.ToString() == "1")
            {
                TextBox txt = new TextBox();
                txt.ID = "txt";
                txt.Width = 150;
                maindiv.Controls.Add(txt);

            }
            if (hdnFieldType.Value.ToString() == "2")
            {
                CheckBoxList chk = new CheckBoxList();
                chk.ID = "chk";
                chk.Items.Add("Same as Student's Home Address");
                chk.RepeatDirection = RepeatDirection.Horizontal;
                maindiv.Controls.Add(chk);
            }

            if (hdnFieldType.Value.ToString() == "4")
            {
                //DropDownList ddl = new DropDownList();
                //ddl.ID = "ddl";

                // ddl.CssClass = "textbox_date";

                DropDownList ddl = new DropDownList();
                ddl.ID = "ddl";
                ddl.Width = 155;
                ddl.CssClass = "dropdown2";



                if (hdnFieldId.Value.ToString() == "1")
                {
                    // schoolcategory.PopulateEvaluationType(ref ddl);
                    StuListCont.PopulateContactRelationship(ref ddl);
                }
                if (hdnFieldId.Value.ToString() == "4")
                {
                    StuListCont.populateState(ref ddl);
                }
              

                maindiv.Controls.Add(ddl);
            }
            if (hdnFieldType.Value.ToString() == "5")
            {
                Label lbl = new Label();
                lbl.ID = "lbl";
                //StudentBL stbl2 = new StudentBL();
                maindiv.Controls.Add(lbl);
            }

            if (hdnFieldType.Value.ToString() == "6")
            {
                var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");

                control.ID = "uc";
                //StudentBL stbl2 = new StudentBL();
                maindiv.Controls.Add(control);
            }



        }
        catch { }


    }


}





